[Zope] adding properties trough pythonscript

Sean Hastings whysean at softhome.net
Mon Oct 18 01:58:47 EDT 2004


I believe that "try: ... except:..." code is only really dangerous if you do
not specify the type of Exceptions that will be caught. The data
inconsistencies become possible when something in the try statement raises a
ConflictError, and your "naked" except statement catches it. It is generally
good coding practice to always explicitly specify what Exception types you
are catching. Assuming that there is only one possible reason that a given
section of code might throw an exception, and therefore failing to specify
what type of Exception it is that you are handling, can lead to some very
hard to debug problems in general, and inconsistent data states with Zope in
particular.

--Sean

> -----Original Message-----
> From: zope-bounces at zope.org [mailto:zope-bounces at zope.org]On Behalf Of
> Dieter Maurer
> Sent: Sunday, October 17, 2004 4:44 PM
> To: massimop at users.berlios.de
> Cc: zope list
> Subject: Re: [Zope] adding properties trough pythonscript
>
>
> massimop at users.berlios.de wrote at 2004-10-16 12:23 +0200:
> > ...
> >> Do not use "try: ... except:...". It is dangerous. It can easily
> >> lead to ZODB inconsistencies...
> >
> >not exactly good news to me....
> >
> >can you point out some document explaining this?
>
> It follows from common sense (and therefore need no documentation ;-)
>
>   Python's exceptions are abortive: as soon an exceptin is raise,
>   the normal flow of control is aborted.
>
>   When you have modified persistent state before the exception occured,
>   the transaction must usually be aborted, to get the modifications
>   reverted. If instead, the transaction is committed, the (often)
>   partial change is made persistent.
>
>   Usually, the Zope framework does this for you.
>   However, when you catch an exception, the framework may
>   not learn about the problem and commit rather than abort.
>
>   As I wrote, this can easily lead to corruption of persistent
>   data.
>
> >can I raise exceptions from a python script?
>
> Yes.
>
> --
> Dieter
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )



More information about the Zope mailing list