You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2015/11/14 21:34:11 UTC
[jira] [Comment Edited] (THRIFT-3388) hash doesn't work on set/list
[ https://issues.apache.org/jira/browse/THRIFT-3388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15005602#comment-15005602 ]
Jens Geyer edited comment on THRIFT-3388 at 11/14/15 8:33 PM:
--------------------------------------------------------------
> since I'm not familiar with the thrift community or its protocols
We don't have that much "protocol" overhead here, so don't worry.
Let me put it this way: If THRIFT-2621 does not solve the whole issue - and it seems pretty much being the case - we should find a solution that does. You as a group, you and the two other guys [~kishorvpatil] and [~tejal29], have toghether probably more than enough Python experience to find the best solution that covers all cases, and eventually put a pull request together that satisfies all needs.
What do you think?
was (Author: jensg):
> since I'm not familiar with the thrift community or its protocols
We don't have that much "protocol" overhead here, so don't worry.
Let me put it this way: If THRIFT-2621 does not solve the whole issue - and it seems pretty much being the case - we should find a solution that does. You as a group, you and the two other guys [~kishorvpatil] and [~tejal29], have toghether probably more than enough Python experience to find the best solution that covers all cases, and eventually put a pull request together that satisfies all sides.
What do you think?
> 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)