On Jun 28, 2011, at 3:45 AM, Torsten Landschoff wrote: > Hi *, > > a while ago I noticed a small problem with SQLAlchemy. I was able to > work around this, but I am still wondering if this should be required. > > I am doing synchronization between multiple databases (think distributed > VCS). Basically, each outdated object on the receiving side is updated > by updating its variables and committing it to the database. > > Now there is some required information in those objects which is checked > in the __init__ method of each class. Therefore to create an object from > the remote object, I am skipping the call to __init__ (like e.g. pickle > does). > > (Interestingly, pickle creates an empty class first and goes to update > __class__ afterwards. Why?!) > > So to create the instances for the mapped objects, I used > > instance = MyClass.__new__(MyClass) > > as in the attached example. This fails with an attribute error for > "_sa_instance_state". My work around is to use > > instance = manager_of_class(MyClass).new_instance() > > but I am wondering if this should be needed, especially since the > ClassManager class is not documented. What should I be using instead?
Instrumentation has to establish state on a new object independent of __new__() - during pickling, the state is restored naturally as __dict__ is restored, during fetch of rows, new_instance() is used, during normal construction, __init__() is used. class_manager() is documented we'd only need to get new_instance() and the use case documented, seems to me that would be bug fixed. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
