Hello there,
maybe anybody has a recipe for optimistic locking with pylons and
sqlalchemy? I've searched the web for 2 days but i didn't find anything,
that nearly helped me with this task. It seems nobody uses locking in a
pylons application with sqlalchemy!?
Maybe i am completely stupid... i wouldn't disagree...
I have tried to use the version_id_col and version_id_generator features
of sqlalchemy like the following excerpt shows:
updated_at = Column(DateTime(), nullable=False, default=datetime.now)
__mapper_args__ = {
'version_id_col': updated_at,
'version_id_generator': lambda v:datetime.now()
}
... but it doesn't work as expected. I thought just a hidden input field
with the updated_at value would do the trick, but as it seems since
version 0.6.4 of sqlalchemy (which i am using) it is not any longer
supported to manually define the version_id_col by simply transfering it
over the client back to server and setting it during the update
procedure like:
o.updated_at =
datetime.strptime(self.form_result[u'updated_at'],'%Y-%m-%d %H:%M:%S.%f')
... but this doesn't work... if i use the above code and use
session.merge(o) and session.commit() it simply updates the updated_at
field to the value of the hidden field and uses the current value from
the database to identify the row, but this wasn't my intention...
My last choice was to simply check for myself and not use the merge
function of the Session object:
count =
s.query(MyTable).filter(MyTable.ID==id).filter(MyTable.updated_at==<updated_at_from_hidden_field>).update(param_dict)
I do not realy want to use self-grown code for this... of course i will,
if it is necessary, but hopefully i am just too stupid to use
version_id_col with pylons.
Does nobody need to use optimistic locking? How do you manage concurrent
modifications of db table entries with pylons and sqlalchemy?
I am using sqlite3... not the best choice... i know... in the future i
will switch to postgres... but as long as the changes are so many
Thank you very much in advance.
Yours
Jan
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.