<div dir="ltr">Hello Chris,<div><br></div><div>I thought it was a bug in SQLAlchemy code, so I wrote a snippet [1] to check my assumption, but I haven't managed to reproduce the problem with SQLAlchemy versions 0.7.9, 0.7.10 and 0.8.2.</div>
<div><br></div><div>I would suggest you to start from enabling logging of all SQL queries SQLAlchemy issues [2] and, if needed, examining of session/model instance state with pdb.</div><div><br></div><div>For your second question. You can set a column to its current value by using of literal_column() expression [3].</div>
<div><br></div><div>Can you elaborate a bit more on your use case? Why do you update the table row, but keep the update_at column value unchanged?</div><div><br></div><div>Thanks,</div><div>Roman</div><div><br></div><div>
[1] <a href="http://paste.openstack.org/show/48335/">http://paste.openstack.org/show/48335/</a></div><div>[2] <a href="https://github.com/openstack/nova/blob/stable/grizzly/nova/openstack/common/db/sqlalchemy/session.py#L296">https://github.com/openstack/nova/blob/stable/grizzly/nova/openstack/common/db/sqlalchemy/session.py#L296</a></div>
<div>[3] <a href="https://github.com/openstack/cinder/blob/master/cinder/db/sqlalchemy/api.py#L1088">https://github.com/openstack/cinder/blob/master/cinder/db/sqlalchemy/api.py#L1088</a></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Oct 12, 2013 at 2:31 AM, Chris Friesen <span dir="ltr"><<a href="mailto:chris.friesen@windriver.com" target="_blank">chris.friesen@windriver.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I'm using grizzly with sqlalchemy 0.7.9.<br>
<br>
I'm seeing some funny behaviour related to the automatic update of "updated_at" column for the Service class in the sqlalchemy model.<br>
<br>
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.<br>
<br>
While trying to do this, I noticed the following behaviour. If I do<br>
<br>
values = {'updated_at': new_value}<br>
self.service_update(context, service, values)<br>
<br>
this sets the "updated_at" column to new_value as expected. However, if I do<br>
<br>
values = {'updated_at': new_value, 'other_key': other_value}<br>
self.service_update(context, service, values)<br>
<br>
then the other key is set as expected, but "updated_at" gets auto-updated to the current timestamp.<br>
<br>
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?<br>
<br>
<br>
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.<br>
<br>
Thanks,<br>
Chris<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</blockquote></div><br></div>