Make db/api strip timezones for datetimes

Before objects, we always used TZ-naive dateteimes, but actually
in the UTC timezone. With objects, we use TZ-aware datetimes with
UTC as the zone. This makes the DB api strip out the timezone
before passing them to sqlalchemy, which expects naive ones.

Related to blueprint compute-api-objects

Change-Id: Id28378c6c68cabcc677bf8cf7b47a4446c397505
This commit is contained in:
Dan Smith
2013-07-09 15:22:12 -07:00
parent 7a9cc2b896
commit 9ed5135165

View File

@@ -2132,6 +2132,13 @@ def _instance_update(context, instance_uuid, values, copy_old_instance=False):
if key in values and values[key] is not None:
values[key] = str(values[key])
# NOTE(danms): Strip UTC timezones from datetimes, since they're
# stored that way in the database
for key in ('created_at', 'deleted_at', 'updated_at',
'launched_at', 'terminated_at', 'scheduled_at'):
if key in values and values[key]:
values[key] = values[key].replace(tzinfo=None)
instance_ref.update(values)
instance_ref.save(session=session)