[
https://issues.apache.org/jira/browse/AVRO-1737?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Michael A. Smith updated AVRO-1737:
-----------------------------------
Environment: Python 3, avro 1.7.7 (was: Python 3.4, avro 1.7.7)
> Unhashable type: 'RecordSchema'
> -------------------------------
>
> Key: AVRO-1737
> URL: https://issues.apache.org/jira/browse/AVRO-1737
> Project: Apache Avro
> Issue Type: Bug
> Components: python
> Affects Versions: 1.7.7
> Environment: Python 3, avro 1.7.7
> Reporter: Zoltan Fedor
> Priority: Major
>
> Following the standard example from
> http://avro.apache.org/docs/current/gettingstartedpython.html but adding a
> dict.get() lookup using an avro.schema.RecordSchema object fails due to
> "unhashable type: 'RecordSchema'"
> This likely happens because the RecordSchema class overwrites the __eq__
> method but does NOT define a __hash__ method.
> Check the Python 3 manual on object.__hash__
> (https://docs.python.org/3.1/reference/datamodel.html?highlight=hash#object.%5F%5Fhash%5F%5F):
> "If a class does not define an __eq__() method it should not define a
> __hash__() operation either; if it defines __eq__() but not __hash__(), its
> instances will not be usable as items in hashable collections."
> TO REPRODUCE the issue run the following script in Python 3 (tested in Python
> 3.4.3):
> {code}
> import avro.schema
> from avro.datafile import DataFileReader, DataFileWriter
> from avro.io import DatumReader, DatumWriter
> schema = avro.schema.Parse(open("users.avsc").read())
> writer = DataFileWriter(open("users.avro", "wb"), DatumWriter(), schema)
> writer.append({"name": "Alyssa", "favorite_number": 256})
> writer.append({"name": "Ben", "favorite_number": 7, "favorite_color": "red"})
> writer.close()
> reader = DataFileReader(open("users.avro", "rb"), DatumReader())
> for user in reader:
> print(user)
> reader.close()
> ### added to generate the error
> test = {}
> test.get(schema, -1)
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)