[openstack-dev] [nova] odd behaviour from sqlalchemy

Chris Friesen chris.friesen at windriver.com
Fri Oct 11 23:31:32 UTC 2013


Hi,

I'm using grizzly with sqlalchemy 0.7.9.

I'm seeing some funny behaviour related to the automatic update of 
"updated_at" column for the Service class in the sqlalchemy model.

I added a new column to the Service class, and I want to be able to 
update that column without triggering the automatic update of the 
"updated_at" field.

While trying to do this, I noticed the following behaviour.  If I do

	values = {'updated_at': new_value}
	self.service_update(context, service, values)

this sets the "updated_at" column to new_value as expected.  However, if 
I do

	values = {'updated_at': new_value, 'other_key': other_value}
	self.service_update(context, service, values)

then the other key is set as expected, but "updated_at" gets 
auto-updated to the current timestamp.

The "onupdate" description in the sqlalchemy docs indicates that it 
"will be invoked upon update if this column is not present in the SET 
clause of the update".  Anyone know why it's being invoked even though 
I'm passing in an explicit value?


On a slightly different note, does anyone have a good way to update a 
column in the Service class without triggering the "updated_at" field to 
be changed?  Is there a way to tell the database "set this column to 
this value, and set the updated_at column to its current value"?  I 
don't want to read the "updated_at" value and then write it back in 
another operation since that leads to a potential race with other 
entities accessing the database.

Thanks,
Chris



More information about the OpenStack-dev mailing list