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

Exceptions on unions of record types #117

Open
dininski opened this issue Apr 26, 2022 · 1 comment
Open

Exceptions on unions of record types #117

dininski opened this issue Apr 26, 2022 · 1 comment

Comments

@dininski
Copy link

dininski commented Apr 26, 2022

A schema with a union of record types internally serializes to a WrappedUnion type. When passing an object, which conforms to the Avro schema, the library will throw an error, because of the ambiguity.

Pseudo code would be something like:

Avro schema:

{
  "type": "record",
  "namespace": "co.uk.ovotech",
  "fields": [{
    "name": "ambiguous",
    "type": [{
      "name": "record_1",
      "fields": [{"name": "record_field", "type": "int"}]
    }, {
      "name": "record_2",
      "fields": [{"name": "record_field", "type": "int"}, {"name": "record_2_another_field", "type": "int"}]
    }]
  }]
}

The following json will throw, even though it is valid:

{
"ambiguous": {"record_field": 1, "record_2_another_field": 2}
}

The way to work around this is include the type as a key on the level above, i.e. this will not throw:

{
  "co.uk.ovotech.record_2": {
    "ambiguous": {"record_field": 1, "record_2_another_field": 2}
  }
}

However this is not a 1-to-1 mapping of the actual avro schema.

If this is not considered an issue, I think at least it should be documented (if it isn't already).

@ivank
Copy link
Contributor

ivank commented May 5, 2022

Where does it error? When building the types or at runtime? Runtime problems are probably from avsc itself and you can probably raise the issue there?

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

2 participants