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.