[Zope] adding properties trough pythonscript

Sean Hastings whysean at softhome.net
Tue Oct 19 14:20:58 EDT 2004


Dieter,

It may be that I do not understand some voodoo going on in Zope control
flow - by what mechanism would either of the code examples below end up with
foo and foo2 in a state inconsistent from the values passed in the last
transaction to finish?


>   Catching *ANY* exception can cause inconsistencies in persistent data.

def fooEdit(self,REQUEST):
	"foo is a string - foo2 is an int"
	self.foo = REQUEST.get('foo','')
	try:
		self.foo2 = int(REQUEST.get('foo2',0)
	except ValueError, e:
		self.foo2 = 0


>   It does (almost surely) when the "try" block modified persistent
>   state before the exception occurred (and you did not ensure that
>   the transaction is aborted).


def fooEdit(self,REQUEST):
	"foo is a string - foo2 is an int"
	try:
		self.foo = REQUEST.get('foo','')
		self.foo2 = int(REQUEST.get('foo2',0)
	except ValueError, e:
		self.foo2 = 0


I am sure that you know more about both Python and Zope than I do, but I
really don't want to believe that the design of Zope prohibits the use of
such a fundamental part of the python language as raising and catching
exceptions.

--Sean

> -----Original Message-----
> From: Dieter Maurer [mailto:dieter at handshake.de]
> Sent: Monday, October 18, 2004 1:36 PM
> To: Sean Hastings
> Cc: massimop at users.berlios.de; zope list
> Subject: RE: [Zope] adding properties trough pythonscript
>
>
> Sean Hastings wrote at 2004-10-18 01:58 -0400:
> >I believe that "try: ... except:..." code is only really
> dangerous if you do
> >not specify the type of Exceptions that will be caught.
>
> I believe you are wrong:
>
>   Catching *ANY* exception can cause inconsistencies in persistent data.
>
>   It does (almost surely) when the "try" block modified persistent
>   state before the exception occurred (and you did not ensure that
>   the transaction is aborted).
>
>
> --
> Dieter



More information about the Zope mailing list