dimanche 19 avril 2015

Timezone info lost in Django save with Postgres

I am saving a model containing a DateTimeField in a Django model. In settings I have USE_TZ = True. Immediately prior to saving the model I am confirming that it is timezone-aware. But when i reload the model it shows tzinfo as None.

Here is an example snippet where I show the execution time and tzinfo before saving and then immediately reload the object

print 'saving TraceRecord'
print record.execution_time, record.execution_time.tzinfo
print record.execution_time, record.execution_time.tzinfo
in_db = trade.TraceRecord.objects.get(trace_control_id=record.trace_control_id)
print in_db.execution_time, in_db.execution_time.tzinfo

and here is the console output

saving TraceRecord
2015-04-17 10:13:18-04:00 US/Eastern
2015-04-17 10:13:18-04:00 US/Eastern
2015-04-17 10:13:18 None

If I look at the sqlall output for the table I see the following:

"execution_time" timestamp with time zone NOT NULL,

Aucun commentaire:

Enregistrer un commentaire