[PonyORM-list] offset aware datetimes => bad idea with pony orm
stephane martin
stef.martin at gmail.com
Tue Aug 26 20:02:54 UTC 2014
hello,
just a short note: ponyorm doesnt feel very comfortable with tz-aware
python datetimes in schemas. That's... well... not a surprise, i shoud
have expected it if i had thought about it 5 minutes.
I have something like:
"""
class Message(db.Entity):
id = PrimaryKey(int, auto=True)
subject = Optional(unicode)
client_hostname = Optional(unicode)
helo_hostname = Optional(unicode)
message_id = Optional(unicode)
importance = Optional(unicode)
priority = Optional(unicode)
sensitivity = Optional(unicode)
size = Optional(int)
content_type = Optional(unicode)
creator_date = Optional(datetime.datetime)
"""
I feed it with a tz-aware creator_date. Creation succeeds, but
afterwards updating the object fails with:
"""
File "<auto generated wrapper of __new__() function>", line 2, in __new__
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/utils.py",
line 64, in cut_traceback
return func(*args, **kwargs)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 3468, in __new__
if attr.reverse: attr.update_reverse(obj, None, val, undo_funcs)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 1484, in update_reverse
if new_val is not None: reverse.__set__(new_val, obj, undo_funcs)
File "<auto generated wrapper of __set__() function>", line 2, in __set__
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/utils.py",
line 64, in cut_traceback
return func(*args, **kwargs)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 1370, in __set__
old_val = attr.load(obj)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 1332, in load
else: obj._load_()
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 3541, in _load_
objects = entity._fetch_objects(cursor, attr_offsets)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 3126, in _fetch_objects
obj._db_set_(avdict)
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",
line 3568, in _db_set_
elif old_dbval == new_dbval:
TypeError: can't compare offset-naive and offset-aware datetimes
"""
IIRC sqlalchemy suffers from that too. Not sure there is an elegant
solution (obviously the pony doesnt know anything about the tz library
im using - pytz). So i probably have to stick to naive datetimes.
Cheers,
Stephane
More information about the ponyorm-list
mailing list