Psycopg2: Incorrect psycopg2.tz.FixedOffsetTimezone after pickling datetimes with different timezones

Created on 21 Oct 2012  路  4Comments  路  Source: psycopg/psycopg2

Originally submitted by: Psycopg website

Submitted by: Robert Saint

>>> before_pickling = []
>>> cur.execute("SET TIME ZONE 'Europe/Rome';")  # UTC + 1 hour
>>> cur.execute("SELECT '2010-01-01 10:30:45'::timestamptz;")
>>> before_pickling.append(cur.fetchone()[0])
>>> cur.execute("SET TIME ZONE 'Europe/Moscow';")  # UTC + 3 hour
>>> cur.execute("SELECT '2010-01-01 10:30:45'::timestamptz;")
>>> before_pickling.append(cur.fetchone()[0])
>>> print before_pickling
[datetime.datetime(2010, 1, 1, 10, 30, 45, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)), 
    datetime.datetime(2010, 1, 1, 10, 30, 45, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=180, name=None))]
>>> after_pickling = pickle.loads(pickle.dumps(before_pickling))
>>> print before_pickling == after_pickling
False
>>> print after_pickling
[datetime.datetime(2010, 1, 1, 10, 30, 45, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=180, name=None)), 
    datetime.datetime(2010, 1, 1, 10, 30, 45, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=180, name=None))]

All 4 comments

What the... Confirmed.

Minimal test:

In [1]: import psycopg2.tz

In [2]: import pickle

In [3]: pickle.loads(pickle.dumps([psycopg2.tz.FixedOffsetTimezone(offset=60), 
    psycopg2.tz.FixedOffsetTimezone(offset=180)]))
Out[3]: 
[psycopg2.tz.FixedOffsetTimezone(offset=180, name=None),
 psycopg2.tz.FixedOffsetTimezone(offset=180, name=None)]

Fixed in my devel and 2.4 maint branch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasonrubenstein picture jasonrubenstein  路  5Comments

pfhayes picture pfhayes  路  5Comments

psycoteam picture psycoteam  路  5Comments

alexjpm picture alexjpm  路  6Comments

mattip picture mattip  路  6Comments