Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Sets are deserialized as lists by TBinaryProtocol, TCompactProtocol #294

Open
terwilliger42 opened this issue Apr 25, 2017 · 1 comment
Open

Comments

@terwilliger42
Copy link

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
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant