Skip to content

cannot pickle dump object from child idl file class #215

@truebit

Description

@truebit

add below code in the end of tests.test_hook.test_load test method:

    # load with sub_module name and it can be pickled
    list_item = ab_2.container.ListItem()
    assert list_item == pickle.loads(pickle.dumps(list_item))

fail log is:

> FAILED                                           [100%]
> tests/test_hook.py:31 (test_load)
> def test_load():
>         ab_1 = thriftpy2.load("addressbook.thrift")
>         ab_2 = thriftpy2.load("addressbook.thrift",
>                               module_name="addressbook_thrift")
>     
>         assert ab_1.__name__ == "addressbook"
>         assert ab_2.__name__ == "addressbook_thrift"
>     
>         # load without module_name can't do pickle
>         with pytest.raises(pickle.PicklingError):
>             pickle.dumps(ab_1.Person(name='Bob'))
>     
>         # load with module_name set and it can be pickled
>         person = ab_2.Person(name='Bob')
>         assert person == pickle.loads(pickle.dumps(person))
>     
>         # load with sub_module name and it can be pickled
>         list_item = ab_2.container.ListItem()
> \>       assert list_item == pickle.loads(pickle.dumps(list_item))
> E       _pickle.PicklingError: Can't pickle <class 'container.ListItem'>: attribute lookup ListItem on container failed
> 
> test_hook.py:50: PicklingError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions