cinder/cinder/tests/unit/objects
Gorka Eguileor cf33a85efb Fix saving tz aware datetimes in Versioned Objects
Currently we cannot save date fields in Versioned Objects because they
are timezone aware and our database is not.

If we look at our objects definition, we are not giving any value to
tzinfo_aware argument, so it takes DateTime default value (True).

In our sqlalchemy model definitions we are defining our datetime fields
as Column(DateTime) which will take sqlalchemy default: class
sqlalchemy.types.DateTime(timezone=False)

In most cases we are accessing those fields directly through the DB
methods, so we don't see the problem, but if we were to modify any of
those fields using versioned object, for example scheduled_at, and then
save the object we'll get an exception:

 File ".../sqlalchemy/sql/type_api.py", line 278, in compare_values
 return x == y
 TypeError: can't compare offset-naive and offset-aware datetimes

Because we are trying to save a timezone aware date to a timezone
unaware DB field.

Following Dan's advice we create a specific cinder_obj_get_changes,
instead of overwriting obj_get_changes, that returns all datefields as
timezone naive UTC datetimes ready for saving.

Change-Id: Ie7b0249e3f6850e7c70d23fc53cfaf27fe04afbb
Closes-Bug: #1469120
2015-07-12 14:16:36 +02:00
..
__init__.py Fix Cinder Objects unit tests 2015-06-22 21:33:34 +03:00
test_backup.py Use elevated context for backup destroy 2015-06-22 18:33:39 +00:00
test_base.py Fix saving tz aware datetimes in Versioned Objects 2015-07-12 14:16:36 +02:00
test_snapshot.py Avoid race condition at snapshot deletion stage 2015-07-02 15:50:01 +03:00
test_volume.py Fix Cinder Objects unit tests 2015-06-22 21:33:34 +03:00