Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime "Duplicate in union" error after generating schema in Scala 3 #819

Open
jchyb opened this issue Feb 8, 2024 · 0 comments
Open

Comments

@jchyb
Copy link

jchyb commented Feb 8, 2024

Hello! Thank you for maintaining this library. I found the following issue when trying to migrate a project to scala 3.

Minimization with scala-cli:

//> using scala "3.3.1"
//> using dep "com.sksamuel.avro4s:avro4s-core_3:5.0.9"
import com.sksamuel.avro4s.SchemaFor

object Repr {
  sealed trait A
  sealed trait B1 extends A
  sealed trait B2 extends A
  case class Test() extends B1 with B2

  def gen() = {
    println(SchemaFor[A].schema)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    Repr.gen()
  }
}

causes (on runtime):

Exception in thread "main" org.apache.avro.AvroRuntimeException: Duplicate in union:Repr.Test
        at org.apache.avro.Schema$UnionSchema.<init>(Schema.java:1238)
        at org.apache.avro.Schema.createUnion(Schema.java:251)
        at org.apache.avro.Schema.createUnion(Schema.java:256)
        at com.sksamuel.avro4s.avroutils.SchemaHelper$.createSafeUnion(SchemaHelper.scala:166)
        at com.sksamuel.avro4s.schemas.TypeUnions$.schema(unions.scala:26)
        at com.sksamuel.avro4s.schemas.MagnoliaDerivedSchemas.split(magnolia.scala:20)
        at com.sksamuel.avro4s.schemas.MagnoliaDerivedSchemas.split$(magnolia.scala:10)
        at com.sksamuel.avro4s.SchemaFor$.split(SchemaFor.scala:55)
        at Repr$.gen(repr.scala:12)
        at Main$.main(repr.scala:18)
        at Main.main(repr.scala)

When replacing scala version with 2.13, and using 4.1.1 version of the library, the schema is successfully generated:

[{"type":"record","name":"Test","namespace":"Repr","fields":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant