Repository navigation
DateTime can't be pickled when the container's timezone was set by copying /etc/localtime - #1040
Conversation
| >>> tz = Timezone('Europe/Paris') | ||
| """ | ||
|
|
||
| _file_bytes: bytes | None = None |
There was a problem hiding this comment.
This is written to, but never used...?
I'm not seeing how this does anything?
There was a problem hiding this comment.
It's the flag and payload __reduce__ needs: if set, it returns _from_pickled_file(data, key) instead of the default, rebuilding the instance from those bytes via from_file() again. Without it, pickling can't reconstruct a file-based instance and crashes - that's the bug this fixes.
Merging this PR will not alter performance
|
Fixes #899.
My app runs in a Docker container where the timezone is set the common Alpine/Debian-slim way -
cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtimeinstead of symlinking it. That's a real, correctly-set timezone, but pendulum'sget_local_timezone()doesn't recognize a copied file as named (it only reads a name fromTZ,/etc/timezone, or a symlink target), so it falls back to reading the raw zoneinfo file directly viaTimezone.from_file(). Anypendulum.now()I then try to pickle (I do this passing results back from amultiprocessing.Pool) crashes with_pickle.PicklingError: Cannot pickle a ZoneInfo file from a file stream, becausezoneinfo.ZoneInfo.from_file()refuses to pickle anything built that way.I know switching the Dockerfile to a symlink avoids this entirely, so arguably this is a deployment-config issue rather than a pendulum one. But
Timezone.from_file()is already a deliberate, supported fallback here, not an error path - so I think it's worth making that fallback fully correct rather than leaving a trap nobody debugging aPicklingErrorwould think to trace back to how/etc/localtimewas set.Kept the raw TZif bytes around on the instance when built via
from_file(), and used them to rebuild an equivalent instance on unpickling instead of inheritingzoneinfo's version, which unconditionally rejects this. RegularTimezone(key)instances still pickle by key as before.