-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot pickle dump object from child idl file class #215
Comments
This is not a bug, it's caused by pickle's behavior. The error is raised from here: https://github.com/python/cpython/blob/main/Modules/_pickle.c#L3695 , as you can see, during the In your example, there is a missleading problem, the module Delete the
We can figure out that pickle is complain that the module By load the module with |
Because the container.thrift is included in the parent addressbook.thrift
file, current load method for parent file would not be able to create a
module name for the child thrift file.
Your workaround would work, but thinking about many recursive includes in
thrift files 😂
I think that would be convenient if we support auto-load of child thrift
files as real module that pickle would recognize ;)
AN Long ***@***.***>于2023年6月14日 周三22:01写道:
This is not a bug, it's caused by pickle's behavior.
The error is raised from here:
https://github.com/python/cpython/blob/main/Modules/_pickle.c#L3695 , as
you can see, during the pickle.dumps process, pickle will try to import
the module.
In your example, there is a missleading problem, the module ab_1.container
is tests/container.thrift actually, and there is a test/container.py file
exists beside the thrift file, and it's actually broken (missing the
ListItem type), which we should fixed in the future (PR is welcomed!).
Delete the container.py, the actually error will be raised:
PicklingError: Can't pickle <class 'container.ListItem'>: import of module 'container' failed
We can figure out that pickle is complain that the module container is
not exist. It's true because we're generating the module on the fly. And
the generated module will not insert into the interpreter's import cache (
sys.modules) if you load it without giving a name, and the module is a
"wild module".
By load the module with thriftpy2.load("container.thrift", module_name =
"container_thrift"), the generated module will be inserted into
sys.modules, which will be used as a cache while importing. So the code
will be worked as expected.
—
Reply to this email directly, view it on GitHub
<#215 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFYJWUB7OEX7YCUFGU45G3XLG73FANCNFSM6AAAAAAZGKTO7Y>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Br,
Sean Wang
Blog: fclef.wordpress.com <http://fclef.wordpress.com/about>
|
I think we should add an option in the load function that enables automatic specification of the module name. For now, you can load the child thrift files beforehand as a workaround. |
I tried to fix this issue, but it seems that only executing test_hook itself would pass the test; when with the whole test suite, test_hook would fail:
|
I tried to fix it in #219 |
Sorry, I've lost the context. does #219 fixed the problem? |
add below code in the end of
tests.test_hook.test_load
test method:fail log is:
The text was updated successfully, but these errors were encountered: