"Owning session has been closed"? Can I still use deepcopy if the session has not been closed? How can I stop it from closing the sessions? The problem is that if I change my shallow copied dictionary, the objects are changed.
Basically, I'm trying to do this state change thing where I'll take a dictionary (let's call it Node 1), make changes to it (thereby making changes to the objects it references) and then save those changes as Node 2. Then I'll take Node 2 and make some changes to that. So on and so forth for a certain number of changes. Everytime I do so, I want to retain the information from the previous Node as well as a "best node" which can be any of the Nodes. If my operations change the objects, is that even possible? That was my motivation to use deepcopy but I don't want to stop using SQLAlchemy because of it :( On Jun 3, 4:57 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Jun 3, 2010, at 1:24 AM, Az wrote: > > > +++ Questions +++ > > > 1. Is this the correct way to use sessions or am I sort of abusing > > them? > > I dont see any poor patterns of use above. > > > 2. When should I close a session? > > when you no longer need the usage of any of the objects associated with it, > or any remaining objects are in a state which you will re-merge them into a > new session before you next use them. The session in its default state of > autocommit=False is just like going to your database and starting a > transaction, doing some work - when you're done with the work, you close the > transaction, and all the data associated with that trans (i.e. your ORM > objects) is essentially "invalid"; other transactions can be modifying that > data. Your objects are an extension of the Session, which should be > considered as an object-oriented window onto a database transaction. > > > 3. I got the following error after trying to use copy.deepcopy() on > > one of my dictionaries. > > > "attribute refresh operation cannot proceed" % (state_str(state))) > > sqlalchemy.exc.UnboundExecutionError: Instance <Project at 0x24c5c50> > > is not bound to a Session; attribute refresh operation cannot proceed > > don't do deepcopy() on a structure that contains ORM objects if their owning > session has been closed. deepcopy on ORM objects probably has issues that > prevent it from working as you'd expect. You'd be better off building copy > constructors, i.e. def copy(self): return FooBar(....). -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.