Robin Munn wrote:

    def OnOK(self, event):
        log.info("Saving...")
        objectstore.commit()
        engine.commit()
        event.Skip()  # Let the event propagate up to the standard handler

    def OnCancel(self, event):
        log.info("Reverting...")
        objectstore.commit()
        engine.rollback()
        event.Skip()  # Let the event propagate up to the standard handler

(I call engine.begin() when the dialog is first presented to the user).

That seems to work, but the OnCancel handler is bugging me. Doing
objectstore.commit() followed immediately by engine.rollback() seems
wrong. I'd like to have an objectstore.rollback() method, but I don't
see one. Should I call objectstore.uow().rollback()? Would that do
what I'm looking for?

I don't think you need to involve the engine at all, using the objectstore should give you all the control you need, i.e the unit of work starts with a call to objectstore.begin(), if you want to update the db with the changes made since you called begin, then call objectstore.commit() - it handles calling commit() on any underlying engine and that particular unit of work is complete.

WRT to rollback, calling objectstore().clear() will remove any objects in the store, which is a fairly heavy-handed way to rollback any changes. As you point out, the uow class has a rollback() which is not exposed at the objectstore level, Mike will no doubt explain why :-). One thing I'm not totally clear on is what happens if you don't call clear() on the objectstore and then call begin() a second time, I'm guessing this behaves the same as nested transactions, but I'm not sure (and I'm too tired to read/understand the code). But, looking at the zblog demo from Myghty which exercises SQLAlchemy fairly well, just doing the begin()/commit() seems to be the way to go.

HTH

Robert



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to