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

Unhashable functions throw error when pickled #139

Closed
ghost opened this issue Dec 5, 2017 · 4 comments
Closed

Unhashable functions throw error when pickled #139

ghost opened this issue Dec 5, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 5, 2017

if obj in _BUILTIN_TYPE_CONSTRUCTORS:

>>> import cloudpickle
>>> dct = {'a': 1}
>>> getter = dct.get
>>> cloudpickle.dumps(getter)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 873, in dumps
    cp.dump(obj)
  File "/usr/local/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 268, in dump
    return Pickler.dump(self, obj)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pickle.py", line 409, in dump
    self.save(obj)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 621, in save_builtin_function
    return self.save_function(obj)
  File "/usr/local/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 340, in save_function
    if obj in _BUILTIN_TYPE_CONSTRUCTORS:
TypeError: unhashable type: 'dict'

Functions cannot be hashed if their closure contains unhashable objects.

Line 340 needs to be wrapped in a try/except block.

@ogrisel
Copy link
Contributor

ogrisel commented Dec 11, 2017

@kelvyang thanks for the bug report. Would you like to submit a pull request with a non-regression test + the fix you suggest?

@ghost
Copy link
Author

ghost commented Dec 25, 2017

@ogrisel unfortunately I can't contribute before acquiring approval from my company. Doing that would require some time, it may be faster for someone else to fix it.

@jakirkham
Copy link
Member

Looks like a dup of the now resolved issue ( #144 ). Could you please retest with master?

@ghost
Copy link
Author

ghost commented Jan 14, 2018

Works now, thanks!

@ghost ghost closed this as completed Jan 14, 2018
This issue was closed.
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

No branches or pull requests

2 participants