Sean Hastings wrote at 2004-10-22 14:53 -0400:
Hopefully, you observe that it does *NOT* depend on the type of errors you are trapping but whether or not you changed (in the try block) persistent state *before* the exception occurred (in this block).
I do not yet understanding that part. My second example was:
1 def fooEdit(self,REQUEST): 2 "foo is a string - foo2 is an int" 3 try: 4 self.foo = REQUEST.get('foo','') 5 self.foo2 = int(REQUEST.get('foo2',0) 6 except ValueError, e: 7 self.foo2 = 0
Here I am modifying the persistent object's "foo" property in line 4, then trapping an exception that the "int" function could raise in line 5. Unless line 4 can also raise a ValueError (and I don't think it can), why am I not safe in assuming one of these three cases?
A. A ValueError raised in line 5 will leave "foo" set properly from the REQUEST, while "foo2" gets set to 0.
B. Some other Exception raised in line 4 or 5 will cause Zope to roll back the transaction and no properties are changed on this try.
C. No Exceptions occur, and leave both properties are set correctly from the REQUEST.
You can assume this. Apparently, you are sure that "A" is acceptable. Carefull consideration is necessary for such cases. If there were some dependancy between "foo" and "foo2", an invariant might get violated. In your case, this seems to be not the case. -- Dieter