Visitar URL original
DateTime of version 3.0+ cannot be pickled without timezone · Issue #899 · python-pendulum/pendulum · GitHub
Skip to content

DateTime of version 3.0+ cannot be pickled without timezone #899

Description

@georgpfolz
  • I am on the latest Pendulum version.

  • [x ] I have searched the issues of this repo and believe that this is not a duplicate.

  • OS version and name: MacOS Sonoma 14.6.1, FreeBSD 13.2

  • Python: 3.11

  • Pendulum version: 2.1.2, 3.0, 3.1.0

Issue

Pickling a pendulum DateTime does not work anymore.

import pickle, pendulum
dt = pendulum.now()
with open("datetime.pkl", "wb") as f:
    pickle.dump(dt, f)

This works fine with pendulum 2.1.2, but in 3.0 or 3.1.0 I get:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
_pickle.PicklingError: Cannot pickle a ZoneInfo file from a file stream.

Activity

  1. changed the title [-]DateTime of version 3.0 cannot be pickled[/-] [+]DateTime of version 3.0+ cannot be pickled[/+] on May 15, 2025
  2. georgpfolz commented on May 15, 2025

    @georgpfolz
    Author

    After doing some more testing, I realized that the problem lies elsewhere: the pickling only fails if the tzinfo of the DateTime object is Timezone('None').

    I wonder why in some cases the local timezone is not used, but the difference between the pendulum versions is that in pendulum 2.1.2 the non-existant tzinfo shows as Timezone('') (as opposed to Timezone('None') in 3.0+).

    I ran into the problem because Zope's Ram Cache Manager (Products.StandardCacheManagers) threw exceptions after upgrading the pendulum version. The traceback showed the pickling error. But everything works fine with a valid timezone.

  3. changed the title [-]DateTime of version 3.0+ cannot be pickled[/-] [+]DateTime of version 3.0+ cannot be pickled without timezone[/+] on May 16, 2025
  4. added this to the Pendulum 3.2 milestone on Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions