youll notice theres a comment saying exactly why the order of these
methods cannot be switched. the solution might be to add a try/except
around oldinit that deregeisters the object.
can you please add a ticket and fully working SQLite example for this ?
it would help me very much.
- mike
Michael Carter wrote:
> Hello,
> I was having an issue that I've since worked around for my app, but I
> think
> it should be reworked in the code. I'm using revision 1222, specifically
> mapper.py lines 250-263. In my project I used __init__ as a place to check
> kwargs and see if they are valid. If not I raise an Exception.
>
> According to the docs in Advanced Data Mapper oldinit is called before
> register_new.
>
> oldinit(self, *args, **kwargs)
> if not nohist:
> # register_new with Unit Of Work
> objectstore.uow().register_new(self)
>
> But in the actual code you can see that register_new is called before
> oldinit
>
> nohist = kwargs.pop('_mapper_nohistory', False)
> session = kwargs.pop('_sa_session',
> objectstore.get_session
> ())
> if not nohist:
> # register new with the correct session, before the
> object's
> # constructor is called, since further assignments
> within the
> # constructor would otherwise bind it to whatever
> get_session() is.
> session.register_new(self)
> if oldinit is not None:
> oldinit(self, *args, **kwargs)
>
> So, is there a reason for oldinit to be called after register_new? When I
> raise an error in my __init__, the row still gets committed when
> objectstore.commit() is called, even though the exception is called. This
> is
> obviously not desirable, so if there isn't a reason for register_new to be
> called first then order should be switched.
>
> -Michael
>
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users