{"action":"closed","issue":{"url":"https://api.github.com/repos/linkedin/python-avro-json-serializer/issues/8","repository_url":"https://api.github.com/repos/linkedin/python-avro-json-serializer","labels_url":"https://api.github.com/repos/linkedin/python-avro-json-serializer/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/linkedin/python-avro-json-serializer/issues/8/comments","events_url":"https://api.github.com/repos/linkedin/python-avro-json-serializer/issues/8/events","html_url":"https://github.com/linkedin/python-avro-json-serializer/issues/8","id":311743046,"number":8,"title":"Incorrect serialization for union of records with overlapping keys","user":{"login":"jesaerys","id":7390563,"avatar_url":"https://avatars2.githubusercontent.com/u/7390563?v=4","gravatar_id":"","url":"https://api.github.com/users/jesaerys","html_url":"https://github.com/jesaerys","followers_url":"https://api.github.com/users/jesaerys/followers","following_url":"https://api.github.com/users/jesaerys/following{/other_user}","gists_url":"https://api.github.com/users/jesaerys/gists{/gist_id}","starred_url":"https://api.github.com/users/jesaerys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jesaerys/subscriptions","organizations_url":"https://api.github.com/users/jesaerys/orgs","repos_url":"https://api.github.com/users/jesaerys/repos","events_url":"https://api.github.com/users/jesaerys/events{/privacy}","received_events_url":"https://api.github.com/users/jesaerys/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-05T19:40:18Z","updated_at":"2018-04-06T00:36:56Z","closed_at":"2018-04-06T00:36:56Z","author_association":"NONE","body":"I'm seeing `AvroJsonSerializer` serialize to the wrong record type in a union. It happens when one record shares a key with another record in the union. Any datum with that common key is always serialized as the first record type in the union.\r\n\r\nFor example,\r\n\r\n```python\r\n>>> import avro.schema\r\n>>> import avro_json_serializer\r\n>>>\r\n>>> schema = avro.schema.SchemaFromJSONData([\r\n...     {'name': 'Foo', 'type': 'record', 'fields': [{'name': 'x', 'type': 'int'}]},\r\n...     {'name': 'Bar', 'type': 'record', 'fields': [{'name': 'x', 'type': 'int'}, {'name': 'y', 'type': 'int'}]},\r\n...     {'name': 'Cow', 'type': 'record', 'fields': [{'name': 'z', 'type': 'int'}]},\r\n... ])\r\n>>> serializer = avro_json_serializer.AvroJsonSerializer(schema)\r\n>>>\r\n>>> data = [{'x': 1}, {'x': 1, 'y': 2}, {'z': 3}]\r\n>>>\r\n>>> list(map(serializer.to_json, data))\r\n['{\"Foo\":{\"x\":1}}', '{\"Foo\":{\"x\":1}}', '{\"Cow\":{\"z\":3}}']\r\n```\r\n\r\nwhere I actually expected to see `['{\"Foo\":{\"x\":1}}', '{\"Bar\":{\"x\":1,\"y\":2}}', '{\"Cow\":{\"z\":3}}']`.\r\n\r\nIf I swap Foo and Bar in the union, then I get the expected result:\r\n\r\n```python\r\n>>> schema = avro.schema.SchemaFromJSONData([\r\n...     {'name': 'Bar', 'type': 'record', 'fields': [{'name': 'x', 'type': 'int'}, {'name': 'y', 'type': 'int'}]},\r\n...     {'name': 'Foo', 'type': 'record', 'fields': [{'name': 'x', 'type': 'int'}]},\r\n...     {'name': 'Cow', 'type': 'record', 'fields': [{'name': 'z', 'type': 'int'}]},\r\n... ])\r\n>>> serializer = avro_json_serializer.AvroJsonSerializer(schema)\r\n>>> list(map(serializer.to_json, data))\r\n['{\"Foo\":{\"x\":1}}', '{\"Bar\":{\"x\":1,\"y\":2}}', '{\"Cow\":{\"z\":3}}']\r\n```\r\n\r\nCow is correctly picked up in both cases."}}
{"actor":{"display_login":"jesaerys"}}