[ZODB-Dev] RE: [Zope-Annce] ZODB 3.2.4 release candidate 1released
Dieter Maurer
dieter at handshake.de
Fri Sep 10 13:08:52 EDT 2004
Tim Peters wrote at 2004-9-9 16:05 -0400:
> ...
>> Let's cast it into a slightly different picture:
>>
>> try:
>> try:
>> # perform modifications on persistent state
>> except ...
>> # do something that does not abort the transaction
>> # and does not raise an exception
>> ...
>> commit()
>> except:
>> abort()
>> ...
>>
>> Should the "perform modifications" result in any exception, then the
>> exception is likely to leave the state inconsitent. Catching the
>> exception causes "commit" to be called which makes the inconsistent state
>> persistent.
>
>OK, that's clear enough. I suggest not writing code that way <wink>.
You get precisely this type of code when you catch exceptions
in Zope -- provided the "try" clause modifies persistent state.
You will not see the "commit" and "abort" (they are part
of the "ZPublisher" framework) but they are there and
behave as indicated in the example.
Thus your advice is the same as mine:
Avoid catching exceptions from code that might have
changed persistent state or ensure that the transaction
is aborted anyway (e.g. by raising the same or a different exception).
--
Dieter
More information about the ZODB-Dev
mailing list