calling __new__ is more equivalent to your objects being "pickled"
and restored from their "pickled" state. in theory whatever state
you set up in your __init__ method when you first create the object,
should have been stored to the database, and then loaded back.
having it use __new__ instead of __init__ allows objects to
differentiate between construction and loading. thats why your
__init__ no longer needs its arguments to be optional.
if you need customized things to be done when the instance is loaded
back from the database, the idea is that youd make a MapperExtension
with create_instance() overridden, which returns a new instance with
whatever else you wanted (i.e. it can just create the object normally):
class MyExt(MapperExtension):
def create_instance(self, mapper, session, row, imap, class_):
return MyObject()
mapper(MyObject, table, extension=MyExt())
On Jun 20, 2006, at 10:23 PM, Robert Leftwich wrote:
> Running with 0.2x (rev 1645) __init__ on my mapped classes is no
> longer being
> called. I note that __new__ is used in 0.2x, but __init__ is not
> called after it
> returns, so is it the intention for >0.2x that any object setup
> that was done in
> __init__ needs to be moved to __new__?
>
> Robert
>
>
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users