Transactions and rollback
I am building a Zope site where a manager enrolls users. A manager completes a form that gathers information about the user. When submitted, the action routine does two things -- .. updates a MySQL database with the user information .. updates acl_users locally to manage the login The MySQL is of a vintage that supports transactions so (per the Zope book) that update will go as a transaction and will either succeed or fail. Likewise, the acl_user update is a transaction and will either succeed or fail. My code needs to keep everything in sync and treat everything as a single transaction, committing only when both the MySQL and the ZOODB updates succeed, otherwise backing out. The problem is figuring out how to do this. Is there a general mechanism? If there isn't, then another approach is to do the acl_user update first since it can be undone (assuming I can get a handle on the transaction), then the MySQL transaction. If the latter fails, I can back out of the acl_user transaction by undoing it. I am using Z SQL methods for the MySQL side of things--they provide a nice wrapper. A few things are unclear from the docs. What exception gets raised by a Z SQL method if it does not commit? On the acl_users side, the updates are managed through External Methods as noted in the code. Currently they just make calls on UserFolder per the in-line documentation. This can fail. For example, what exception is raised when an attempt is made to add a name already in use. (Are these documented somewhere?) I presume that an exception in the External Method will get exported out to an enclosing <dtml-try> block so it can be captured and delt with in the web portion of the system. If I need to back off a committed transaction in the ZOODB, how is that done programatically. Presumably I can do the equivalent of the undo management screen progrmatically, but to do do, I need the handle of the transaction I want/need to undo. I don't see how to get it. Thanks for help.
Dennis Allison writes:
I am building a Zope site where a manager enrolls users. A manager completes a form that gathers information about the user. When submitted, the action routine does two things --
.. updates a MySQL database with the user information .. updates acl_users locally to manage the login
Use "exUserFolder" to get the user information directly from the MySQL database. Forget about the standard "acl_users"... Dieter
participants (2)
-
Dennis Allison -
Dieter Maurer