Skip to content

Commit

Permalink
objects: restore some datetime field comments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markmc committed Apr 29, 2014
1 parent 0d4d94e commit b6e71f4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nova/objects/fields.py
Expand Up @@ -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

Expand Down

0 comments on commit b6e71f4

Please sign in to comment.