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

Add hash func for UnionSchema #228

Merged
merged 1 commit into from
Aug 14, 2017

Conversation

simonwahlgren
Copy link
Contributor

@simonwahlgren simonwahlgren commented Aug 14, 2017

Hey!

I've found a bug (confluent-kafka==0.11.0) using unions at top level in schemes which results in the following error:

Traceback (most recent call last):              
...                      
  File "/usr/lib/python3.6/site-packages/confluent_kafka/avro/cached_schema_registry_client.py", line 123, in register
    schema_id = schemas_to_id.get(avro_schema, None)                                            
TypeError: unhashable type: 'UnionSchema'

You can reproduce it like this:

from confluent_kafka.avro import AvroProducer

value_schema = avro.load('schemas/order.events-value.avsc')
key_schema = avro.load('schemas/order.events-key.avsc')

config = {
    'bootstrap.servers': 'localhost:9092',
    'schema.registry.url': 'http://localhost:8081'
}
producer = AvroProducer(config, default_value_schema=value_schema,
                        default_key_schema=key_schema)

value = {'class': 'OrderCreated', 'data': {'order_id', '1'}}
producer.produce(topic='order.events', key='1', value=value)
producer.flush()

order.commands-value.avsc:

[
    {
        "type": "record",
        "name": "MessageData",
        "namespace": "order.common",
        "fields": [
            {
                "name": "order_id",
                "doc": "order_id",
                "type": "string",
                "logicalType": "uuid"
            }
        ]
    },
    {
        "name": "commands",
        "namespace": "order",
        "type": "record",
        "doc": "Order commands",
        "fields": [
            {
                "name": "class",
                "doc": "Message class",
                "type": "string"
            },
            {
                "name": "data",
                "doc": "Message data",
                "type": "order.common.MessageData"
            }
        ]
    }
]

This PR fixes this issue by manually adding a hash func to UnionSchema.

@ghost
Copy link

ghost commented Aug 14, 2017

It looks like @simonwahlgren hasn't signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement here.

Once you've signed reply with [clabot:check] to prove it.

Appreciation of efforts,

clabot

@simonwahlgren
Copy link
Contributor Author

[clabot:check]

@ghost
Copy link

ghost commented Aug 14, 2017

@confluentinc It looks like @simonwahlgren just signed our Contributor License Agreement. 👍

Always at your service,

clabot

Copy link
Contributor

@edenhill edenhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@edenhill edenhill merged commit 9ba492a into confluentinc:master Aug 14, 2017
@simonwahlgren simonwahlgren deleted the unionschema_hash_func branch April 4, 2018 12:20
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

Successfully merging this pull request may close these issues.

None yet

2 participants