python3: unpickle tzinfo pickled with python2

Bug #1631989 reported by ricolai
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pytz
Fix Released
High
Unassigned

Bug Description

Hi,

Yes, pickle is not guaranteed to be cross-compatible between python versions, but it's so close !!

----------

Dump in python 2:

import pickle, pytz, datetime
with open("date.pickle", "wb") as fp:
    pickle.dump(pytz.timezone('Europe/Paris').localize(datetime.datetime(2016, 1, 1)), fp)

----------

Load in python 3:

import pickle
with open("date.pickle", "rb") as fp:
    pickle.load(fp, encoding="bytes") # encoding="bytes" so that pickle can load old str
# fails with
# AttributeError: 'bytes' object has no attribute 'encode'
# because pytz.zone calls 'ascii(zone)' for something that is already in bytes

---------

pytz.ascii should not .encode 'bytes', that's it !

Thanks !

Stuart Bishop (stub)
Changed in pytz:
status: New → Triaged
importance: Undecided → High
Stuart Bishop (stub)
Changed in pytz:
status: Triaged → Fix Committed
Stuart Bishop (stub)
Changed in pytz:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.