yeah, i dont even have to run it since youve pretty much analyzed the problem completely. So yeah, taking off the _instance_key effectively sets the object as "transient" as opposed to "persistent", i.e. unsaved.
that approach will probably work for now, you might want to also expunge() the object from the session first before switching the instance key so that the object is placed into the session completely with its blank identity, and isnt tied to its previous identity. The usage of two mappers here suggests that you might want to be using "entity_name" to keep them straight. Perhaps we could add functionality onto the Session to provide the service of "switching the entity name" of an instance, or more likely returning a new, transient instance that is a copy of the old one (copying objects is something the SA session needs to get better at, for example to support the merge() function). i think stick with the somewhat hacky way for now (or maybe we'll start to consider it less hacky....), maybe look into "entity-name" since thats more the "official" way to have two mappers for one class, and ill see if i can think of a way this should work....it blends into the work that needs to be done for session.merge() which i think is going to be a little involved. On Aug 17, 2006, at 5:28 PM, Antonin ENFRUN wrote: > Here is a short test program. > > In fact, the problem seems to be that SQLAlchemy try to UPDATE an > object loaded from the secondary mapper, as this object's got an > _instance_key. > > As the script demonstrate, removing the _instance_key forces > SQLAlchemy to INSERT. But I don't think that messing with > _instance_key is safe... Taking this situation into account when > deciding to insert or update in mapper.save_obj seems to be the good > solution, but i'm new to SQLAlchemy and it may be more complicated > than that... > > Please tell me if I can be of any help with this. > <sa test.py> > ---------------------------------------------------------------------- > --- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642______________________________ > _________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users