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/            p...@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to