Permalink
Browse files

Ensure proper timezone handling of data passed to update() and create()

This ensures data passed directly into the .update() and create()
methods of a DBDataWrite class is properly made timezone-aware by
converting to the modified datetime class, before being pushed to the
database.
  • Loading branch information...
wagnerrp committed Sep 20, 2012
1 parent 3128dac commit 44ebd807fa4b0b047a855f2e8a8c3dcd16cb5e77
Showing with 15 additions and 3 deletions.
  1. +15 −3 mythtv/bindings/python/MythTV/database.py
@@ -133,7 +133,7 @@ def fromRaw(cls, raw, db=None):
return dbdata
def __setitem__(self, key, value):
for k,v in self._db.tablefields[self._table].items():
for k,v in self._field_order.items():
if k == key:
if v.type in ('datetime','timestamp'):
value = datetime.duck(value)
@@ -181,7 +181,7 @@ def __init__(self, data, db=None):
def _process(self, data):
data = DictData._process(self, data)
for key, val in self._db.tablefields[self._table].items():
for key, val in self._field_order.items():
if (val.type in ('datetime','timestamp')) \
and (data[key] is not None):
data[key] = datetime.fromnaiveutc(data[key])
@@ -331,6 +331,12 @@ def _create(self, data=None, cursor=None):
self._create(data, cursor)
return
if data is not None:
for k,v in self._field_order.items():
if (k in data) and (data[k] is not None) and \
(v.type in ('datetime','timestamp')):
data[k] = datetime.duck(data[k])
self._import(data)
data = self._sanitize(dict(self))
for key,val in data.items():
@@ -407,7 +413,13 @@ def update(self, *args, **keywords):
data = {}
data.update(*args, **keywords)
dict.update(self, self._sanitize(data))
data = self._sanitize(data)
for k in data:
if self._field_order[k].type in ('datetime', 'timestamp'):
data[k] = datetime.duck(data[k])
dict.update(self, data)
self._push()
def delete(self):

0 comments on commit 44ebd80

Please sign in to comment.