You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Michael A. Smith (Jira)" <ji...@apache.org> on 2019/11/17 02:28:00 UTC

[jira] [Commented] (AVRO-1737) Unhashable type: 'RecordSchema'

    [ https://issues.apache.org/jira/browse/AVRO-1737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16975869#comment-16975869 ] 

Michael A. Smith commented on AVRO-1737:
----------------------------------------

I believe the best way to define {{hash}} for schema is by their fingerprint. So I think once AVRO-1938 is merged doing this will become pretty trivial.

> 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)