Re: [SQLObject] InheritableSQLObject: Data corruption when child record create fails
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2009-12-07 18:28:34
|
Hi! On Mon, Dec 07, 2009 at 06:41:54PM +0200, Tom Coetser wrote: > The problem is that when creating a new object based on an > InheritableSQLObject class, and the creation of the child object fails after > a new parent was created, the parent record will remain in the database > without the relevant child. A valid concern, sure. I never stumbled upon the problem because I always use transactions, and on any exception I just ABORT the transaction; on ABORT the DB removes the half created parent. > I'm attaching a patch as a possible fix for this Thank you! > - super(InheritableSQLObject, self)._create(id, **kw) > + # TC: Create this record and catch all exceptions in order to destroy > + # TC: the parent if the child can not be created. > + try: > + super(InheritableSQLObject, self)._create(id, **kw) > + except: > + # TC: If we are the child, destroy the parent > + if self.sqlmeta.parentClass: > + self._parent.destroySelf() > + self._parent = None > + # TC: Reraise the original exception > + raise > + The patch looks rather simple and straightforward. I'll test it. Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |