Hi, Of the top of my head I think you need to use with_lockmode in SQLAlchemy to create a query that locks the rows in the database for updating. I'm not sure what DB's support this on a per row basis (you may end up locking an entire table, Postgres does row locking but I don't think MySQL does).
The current in_use=True and commit isn't going to work with concurrent users. Hope that helps. On Fri, Nov 27, 2009 at 6:18 PM, James <[email protected]> wrote: > Hi all, > I have a method which is quite long running; an object needs to be > marked as 'in use' in the DB while the method is active. > > When I was using TG1, doing something like: > def long_method(obj) > obj.in_use = True > model.session.commit() > # do long-running stuff > obj.in_use = False > model.session.commit() > > Worked just fine. However, in TG2, using transaction.commit() instead > of model.session.commit() causes all ORM objects to become > invalidated, and I need to re-query the DB to get a fresh instance, > e.g.: > def long_method(obj) > obj.in_use = True > obj_id = obj.id > transaction.commit() > # do long-running stuff > obj = model.MyObject.query.get(obj_id) > obj.in_use = False > transaction.commit() > > This feels a bit awkward, and the real code is obviously quite a bit > more complex which doesn't help. Am I misusing the TG model tools > available to me, or is re-querying really the best approach? > > Thanks! > James > > -- > > You received this message because you are subscribed to the Google Groups > "TurboGears" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<turbogears%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/turbogears?hl=en. > > > -- be seeing you dazza -- You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en.

