[sqlalchemy] Re: Multiple database connections - Using ORM to copy table data from one DB to another
I had originally tried the expunge method, as in the code I had attached, but if I just use session.save(policy), I get the aforementioned exception, and if I use session.save_or_update(policy) it simply does nothing. When using session.merge(policy), I get the following exception: File build\bdist.win32\egg\sqlalchemy\orm\session.py, line 483, in merge NameError: global name 'mapperutil' is not defined Regarding the eager-loading, I understand that the configuration of the mappers will be in effect. I meant to inquire as to whether there was a way to recursively override the mappers, as this is a different use than the ORM was originally intended for, and the usual behavior of lazy-loading is not desired here. I considered using the eagerload option, but my ORM has several levels (eg, Policy contains Insureds which each contain Addresses) and it didn't seem like the option would apply all the way down. -Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] Behalf Of Michael Bayer Sent: Saturday, September 22, 2007 11:11 AM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: Multiple database connections - Using ORM to copy table data from one DB to another 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. CONFIDENTIAL NOTICE: This email including any attachments, contains confidential information belonging to the sender. It may also be privileged or otherwise protected by work product immunity or other legal rules. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information is strictly prohibited. If you have received this email in error, please immediately notify us by reply email of the error and then delete this email immediately. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Multiple database connections - Using ORM to copy table data from one DB to another
On Oct 2, 2007, at 10:32 AM, Cory Johns wrote: I had originally tried the expunge method, as in the code I had attached, but if I just use session.save(policy), I get the aforementioned exception, and if I use session.save_or_update(policy) it simply does nothing. When using session.merge(policy), I get the following exception: File build\bdist.win32\egg\sqlalchemy\orm\session.py, line 483, in merge NameError: global name 'mapperutil' is not defined thats a bug in the exception throw. if you upgrade to 0.4 or the latest trunk of 0.3 its fixed (I recommend 0.4). the error message it would like to show you is: Instance %s has an instance key but is not persisted which means, you are artifically attaching an _instance_key to the object but its not actually present in the database. if youre copying over to a new database, remove the _instance_key attribute from the object before merging it or saving to the new session; otherwise it thinks no changes are needed. Regarding the eager-loading, I understand that the configuration of the mappers will be in effect. I meant to inquire as to whether there was a way to recursively override the mappers, as this is a different use than the ORM was originally intended for, and the usual behavior of lazy-loading is not desired here. I considered using the eagerload option, but my ORM has several levels (eg, Policy contains Insureds which each contain Addresses) and it didn't seem like the option would apply all the way down. the eagerload options do apply to multiple levels.in 0.3 you need to specify a separate eagerload() option for each path, i.e. query.options(eagerload('a'), eagerload('a.b'), eagerload('a.b.c')) in 0.4 just use query.options(eagerload_all('a.b.c')) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Multiple database connections - Using ORM to copy table data from one DB to another
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 -~--~~~~--~~--~--~---