thriftpy icon indicating copy to clipboard operation
thriftpy copied to clipboard

Sets are deserialized as lists by TBinaryProtocol, TCompactProtocol

Open terwilliger42 opened this issue 7 years ago • 1 comments

When deserializing a thrift struct which contains a set, it is read into the object as a list, not as a set.

For example:

import thriftpy
from thriftpy.utils import serialize, deserialize
from thriftpy.protocol import TCompactProtocolFactory
from io import StringIO

thrift_spec = """
struct Test {
    1: set<i32> some_set
}
"""
thriftpy.load_fp(StringIO(thrift_spec), "test_thrift")
from test_thrift import Test

pf = TCompactProtocolFactory()
x = Test(some_set={1, 2, 3})
y = deserialize(Test(), serialize(x, pf), pf)
print("Source:       {!r}".format(x))
print("Deserialized: {!r}".format(y))
assert x == y

Output:

Source:       Test(some_set={1, 2, 3})
Deserialized: Test(some_set=[1, 2, 3])
Traceback (most recent call last):
  File "./dump_results", line 131, in <module>
    assert x == y
AssertionError

terwilliger42 avatar Apr 25 '17 20:04 terwilliger42

Can I assume that the correct behavior is to use the Python set type in this case?

If so, I will happily provide a PR which addresses this issue.

terwilliger42 avatar Apr 25 '17 20:04 terwilliger42