[ https://issues.apache.org/jira/browse/THRIFT-3388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15005591#comment-15005591 ]
John Sirois commented on THRIFT-3388: ------------------------------------- [~jensg] One appropriate fix seems like a revert. THRIFT-2621 ~lifted a patch striaght from [here|https://github.com/nathanmarz/thrift/commit/6d4b008512cd9fcd5a6bb598d09f35eaf2dc7412] that was appropriate in its original context but it does not seem appropriate to ship with the official Apache thrift. It breaks very common use cases in thrift, namely using map, set, list. It would help to understand [~kishorvpatil]'s use case for THRIFT-2621, since a revert would break presumably break his work. My guess is wanting to avoid writing custom wrappers or keys for thrift structs for use in unit test comparisons and as members of application-level dicts and sets. Increasing the fix complexity, but being sensitive to [~kishorvpatil]'s use case would mean adding deep hash/eq as an option, there is precedent for this in {{java:hashcode}}. Interested in your opinions in particular since I'm not familiar with the thrift community or its protocols on things like this. > hash doesn't work on set/list > ----------------------------- > > Key: THRIFT-3388 > URL: https://issues.apache.org/jira/browse/THRIFT-3388 > Project: Thrift > Issue Type: Bug > Components: Python - Compiler > Affects Versions: 0.9.3 > Environment: ubuntu 14.04 python 2.6.9 > Reporter: Michi Mutsuzaki > > THRIFT-2621 added hash function to thrift generated classes, but certain > types like set or list cannot be hashed. One solution is to convert them to > immutable types (fronzenset, tuple) before calling hash() on them. > {noformat} > $ thrift -version > Thrift version 0.9.3 > $ cat test.thrift > struct Test { > 1: required set<string> test > } > $ thrift --gen py -out . test.thrift > $ cat test.py > from test.ttypes import Test > from thrift.protocol import TBinaryProtocol > from thrift.transport import TTransport > # serialize > t = Test(test=set(["a"])) > tout = TTransport.TMemoryBuffer() > pout = TBinaryProtocol.TBinaryProtocol(tout) > t.write(pout) > # deserialize > tin = TTransport.TMemoryBuffer(tout.getvalue()) > pin = TBinaryProtocol.TBinaryProtocol(tin) > t2 = Test() > t2.read(pin) > # put the deserialized object to a set > a = set([t2]) > $ python test.py > Traceback (most recent call last): > File "test.py", line 18, in <module> > a = set([t2]) > File "/tmp/test/test/ttypes.py", line 81, in __hash__ > value = (value * 31) ^ hash(self.test) > TypeError: unhashable type: 'set' > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)