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

Use only the highest, premium quality pickler available at runtime. #156

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

akatrevorjay
Copy link
Contributor

@akatrevorjay akatrevorjay commented Jun 1, 2017

Also include a forewarning note on Python "pickleableness".

This also allows easier changing as it's now a constant. While not perfect, it's certainly helpful for me at least!

The issue with version 0 is that some objects which should be pickleable are not.

Namely this scenario:

  • An object defines __getstate__ to select the state to be pickled and restored.
  • This object contains a non-pickleable slotted object in an attribute value (ie defines __slots__)
  • Said attribute happens to be specifically excluded from the state dictionary returned from __getstate__ of it's parent, but alias, cPython with pickle version zero returns:

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

Fun stuff. Thanks for the lib.

Also include a forewarning note on Python "pickleableness".
# state via `__getstate__`, python will complain with something like:
# TypeError: a class that defines __slots__ without defining __getstate__
# cannot be pickled
PICKLE_VERSION = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because -1 is always the highest protocol.

Copy link
Contributor Author

@akatrevorjay akatrevorjay Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use the const if you want, but using -1 is pretty standard imo and doesn't have an attr lookup tax (which is of course not worth mentioning though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, in python 3 the default is the new py3+ pickle. But in pymemcache, we always use zero and it unfortunately is a pretty broken version :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgordon looks like you added this originally any specific reason for the old behavior? Looks like this is based on https://github.com/linsomniac/python-memcached/blob/5b75728565393d53768f4622fdd43e3e742c4741/memcache.py

Also this is a a backwards incompatible change.

Perhaps it would be better to make this field an argument that can be set?

@akatrevorjay akatrevorjay changed the title Use only the highest, premium quality picklers available at runtime. Also include a forewarning note on Python "pickleableness". Use only the highest, premium quality picklers available at runtime. Jun 2, 2017
@akatrevorjay akatrevorjay changed the title Use only the highest, premium quality picklers available at runtime. Use only the highest, premium quality pickler available at runtime. Jun 2, 2017
Copy link
Collaborator

@nichochar nichochar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I don't have a strong opinion about -1 vs HIGHEST_PROTOCOL, and this seems like an improvement.

Thanks for the change @akatrevorjay

@nichochar nichochar merged commit 78afc60 into pinterest:master Jun 2, 2017
@cgordon
Copy link
Collaborator

cgordon commented Jun 2, 2017

@jogo Yes, the "python_memcache_[de]serializer" functions are meant to emulate the default behavior of the python-memcache library. If this breaks that functionality, it is going to hurt all the people (including Pinterest) that rely on it. If -1 and 0 are compatible then this change is fine.

@akatrevorjay
Copy link
Contributor Author

akatrevorjay commented Jun 2, 2017 via email

@akatrevorjay
Copy link
Contributor Author

akatrevorjay commented Jun 2, 2017 via email

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

Successfully merging this pull request may close these issues.

4 participants