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

Cannot pickle datetime object with timezone #12

Closed
jappievw opened this issue Nov 5, 2018 · 5 comments
Closed

Cannot pickle datetime object with timezone #12

jappievw opened this issue Nov 5, 2018 · 5 comments
Labels
bug Something isn't working

Comments

@jappievw
Copy link

jappievw commented Nov 5, 2018

Thanks for providing this awesome backport! Today I ran into the issue that a datetime object can't be pickled when it includes a timezone. Please find the example below:

$ python
Python 3.6.5 (default, Mar 30 2018, 06:41:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> import datetime
>>> from backports.datetime_fromisoformat import MonkeyPatch
>>> MonkeyPatch.patch_fromisoformat()
>>> moment = datetime.datetime.fromisoformat('2018-11-01 20:42:09.058000+00:00')
>>> pickle.dumps(moment)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'FixedOffset_type'>: attribute lookup FixedOffset_type on builtins failed
>>> moment = datetime.datetime.fromisoformat('2018-11-01 20:42:09.058000')
>>> pickle.dumps(moment)
b'\x80\x03cdatetime\ndatetime\nq\x00C\n\x07\xe2\x0b\x01\x14*\t\x00\xe2\x90q\x01\x85q\x02Rq\x03.'

Unfortunately, I lack the skills to create a PR to resolve this.

@movermeyer
Copy link
Owner

Hey @jappievw, thanks for the bug report.

I can reproduce this behaviour.

Unfortunately, I also lack the skills to know how to resolve this.

The problem exists in the underlying library I copied the timezone code from.

I've raised an issue with them, so hopefully I can learn some more.

@jappievw
Copy link
Author

jappievw commented Nov 7, 2018

Thanks for your update @movermeyer. I will subscribe to that issue as well!

@movermeyer
Copy link
Owner

movermeyer commented Nov 15, 2018

I've gone and learned how pickling/copying works.
The fix has been made, and a new version released.

This problem should be fixed.

@jappievw
Copy link
Author

jappievw commented Nov 15, 2018 via email

@jappievw
Copy link
Author

Implemented it, thanks for your effort @movermeyer!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants