From b6e71f4524c0fece34e2f7e2a8d3176538538912 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 29 Apr 2014 11:43:48 +0100 Subject: [PATCH] objects: restore some datetime field comments The datetime coercion code in nova.objects.utils had a couple of helpful comments which were lost when the code was refactored into nova.objects.fields. Change-Id: If23320dd8780a1947ad4d5946c55e1e8794b782f --- nova/objects/fields.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nova/objects/fields.py b/nova/objects/fields.py index 3ac6257b..ccf81388 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -246,11 +246,16 @@ class DateTime(FieldType): @staticmethod def coerce(obj, attr, value): if isinstance(value, six.string_types): + # NOTE(danms): Being tolerant of isotime strings here will help us + # during our objects transition value = timeutils.parse_isotime(value) elif not isinstance(value, datetime.datetime): raise ValueError(_('A datetime.datetime is required here')) if value.utcoffset() is None: + # NOTE(danms): Legacy objects from sqlalchemy are stored in UTC, + # but are returned without a timezone attached. + # As a transitional aid, assume a tz-naive object is in UTC. value = value.replace(tzinfo=iso8601.iso8601.Utc()) return value