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)But in the actual code you can see that register_new is called before oldinit
if not nohist:
# register_new with Unit Of Work
objectstore .uow().register_new (self)
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