Skip to content
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

Pickling problematic with Python 2 #311

Closed
chrisrossi opened this issue Jan 30, 2020 · 0 comments · Fixed by #330
Closed

Pickling problematic with Python 2 #311

chrisrossi opened this issue Jan 30, 2020 · 0 comments · Fixed by #330
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@chrisrossi
Copy link
Contributor

chrisrossi commented Jan 30, 2020

When Danny started the NDB port, he was fond of using __slots__, since classes which use them have better performance than classes which rely on a dict for class attributes. However, as I just learned today, pickle doesn't support classes with __slots__ under Python 2, so you can get errors when trying to pickle an NDB entity under Python 2. (I'm not sure pickling is the best way to serialize NDB entities, but at least some users do this, for better or for worse.)

When attempting to pickle a class with slots, you get the following error:

TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled

A test which exposes one such error is in tests.system.test_misc.test_pickle_roundtrip_structured_property (added in #312).

@chrisrossi chrisrossi added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Jan 30, 2020
@andrewsg andrewsg added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Jan 30, 2020
@chrisrossi chrisrossi self-assigned this Feb 10, 2020
chrisrossi pushed a commit to chrisrossi/python-ndb that referenced this issue Feb 11, 2020
In Python 2.7, classes which use `__slots__` can't be pickled. Users
have reported problems trying to pickle NDB entities, indicating there
is some perceived use case for pickling entities.

Fixes googleapis#311
chrisrossi pushed a commit that referenced this issue Feb 11, 2020
In Python 2.7, classes which use `__slots__` can't be pickled. Users
have reported problems trying to pickle NDB entities, indicating there
is some perceived use case for pickling entities.

Fixes #311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants