On Sep 18, 2007, at 5:47 PM, Cory Johns wrote:

> I'm trying to make a small utility that uses a larger application's  
> ORM to
> copy an object from one database (dev) to another (qa) for testing  
> purposes.
> But I'm running in to trouble getting SQLAlchemy to use the multiple
> database connections.  I can get the object to load, and then open a
> connection to the other database, but when I try to call save, I  
> get the
> following error:
>
>       sqlalchemy.exceptions.InvalidRequestError: Instance
> '<thig.base.model.policy.Policy object at 0x018C5AB0>' is a detached
> instance or is already persistent in a different Session
>
> Is it possible to re-attach an ORM instance to a new session in  
> order to
> duplicate the data to another database like I'm doing?  If so, how  
> do I go
> about that?

use session.merge() is probably the most straightforward way (returns  
a second object instance associated with the new session).  or, you  
can expunge() the object from the first session, then save_or_update 
() to the second session.

>
> Additionally, as I suspect this will be a problem once I get it re- 
> attached,
> is there an easy way to specify that all properties, recursively,  
> should be
> eager loaded?

whatever the configuration is of the mappers() representing the  
involved classes will remain in effect.



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to