kvesteri/sqlalchemy-utils — pull request #66 by nickretallack (2014-02-14 02:00:18+00:00)
Title: Fixed ArrowType to store and retrieve time consistently.

SQLAlchemy's handling of time is stupid. If you hand it a datetime with an explicit time zone set, and attempt to put it in a "timestamp without time zone" field, it will convert it to your local time first. This is probably not what you want! Especially for ArrowType, because when you retrieve the value and pass it to arrow.get, arrow assumes the time is in UTC, when it's really in local time. This leads to nonsense like this:

myrecord.time = time
db.session.commit()
myrecord.time != time # wtf! It changed!

In this commit, I make the assumption that you always want to put UTC timestamps into your database, so I convert the incoming time to UTC and then discard the time zone so SQLAlchemy wont mess with it.

A future version of this type might allow you to specify what time zone you want to assume this database column actually represents, so you can convert to and from that time zone when saving and retrieving.