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?

Greetings, Torsten

-- 
DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
Torsten Landschoff

Office Dresden
Tel: +49-(0)351-4519587
Fax: +49-(0)351-4519561

mailto:torsten.landsch...@dynamore.de
http://www.dynamore.de

Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
Managing director:  Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.orm.attributes import manager_of_class

metadata = MetaData()

class Base(object): pass

base_table = Table("base", metadata,
    Column("id", Integer, primary_key=True),
    Column("name", String))

mapper(Base, base_table)

b = Base()
assert b.name is None

b = manager_of_class(Base).new_instance()
b.name = "using manager_of_class"

b = Base.__new__(Base)
b.name = "using __new__"

Reply via email to