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].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.