<div dir="ltr">Thanks for the reporting, I will investigate what is the best way of dealing with tz-aware datetimes.<br><br>One possible solution is this: when tz-aware datetime is assigned as an attribute value of entity instance, it is immediately converted to naive UTC datetime. On attribute read its value is converted to tz-aware local datetime. I will think about implementing such functionality.<br>
<br>PostgreSQL has special datatype for datetimes with timezone, maybe we should add support for this.<br><br>Regards,<br>Alexander Kozlovsky</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 27, 2014 at 12:02 AM, stephane martin <span dir="ltr"><<a href="mailto:stef.martin@gmail.com" target="_blank">stef.martin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">hello,<br>
<br>
just a short note: ponyorm doesnt feel very comfortable with tz-aware<br>
python datetimes in schemas. That's... well... not a surprise, i shoud<br>
have expected it if i had thought about it 5 minutes.<br>
<br>
I have something like:<br>
<br>
"""<br>
class Message(db.Entity):<br>
id = PrimaryKey(int, auto=True)<br>
subject = Optional(unicode)<br>
client_hostname = Optional(unicode)<br>
helo_hostname = Optional(unicode)<br>
message_id = Optional(unicode)<br>
importance = Optional(unicode)<br>
priority = Optional(unicode)<br>
sensitivity = Optional(unicode)<br>
size = Optional(int)<br>
content_type = Optional(unicode)<br>
creator_date = Optional(datetime.datetime)<br>
"""<br>
<br>
I feed it with a tz-aware creator_date. Creation succeeds, but<br>
afterwards updating the object fails with:<br>
<br>
"""<br>
File "<auto generated wrapper of __new__() function>", line 2, in __new__<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/utils.py",<br>
line 64, in cut_traceback<br>
return func(*args, **kwargs)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 3468, in __new__<br>
if attr.reverse: attr.update_reverse(obj, None, val, undo_funcs)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 1484, in update_reverse<br>
if new_val is not None: reverse.__set__(new_val, obj, undo_funcs)<br>
File "<auto generated wrapper of __set__() function>", line 2, in __set__<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/utils.py",<br>
line 64, in cut_traceback<br>
return func(*args, **kwargs)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 1370, in __set__<br>
old_val = attr.load(obj)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 1332, in load<br>
else: obj._load_()<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 3541, in _load_<br>
objects = entity._fetch_objects(cursor, attr_offsets)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 3126, in _fetch_objects<br>
obj._db_set_(avdict)<br>
File "/Users/steph/dev/manager_env/lib/python2.7/site-packages/pony/orm/core.py",<br>
line 3568, in _db_set_<br>
elif old_dbval == new_dbval:<br>
TypeError: can't compare offset-naive and offset-aware datetimes<br>
"""<br>
<br>
IIRC sqlalchemy suffers from that too. Not sure there is an elegant<br>
solution (obviously the pony doesnt know anything about the tz library<br>
im using - pytz). So i probably have to stick to naive datetimes.<br>
<br>
Cheers,<br>
Stephane<br>
_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
</blockquote></div><br></div>