[sqlalchemy] Re: Cannot delete persisted object which is not in current session

2008-07-01 Thread Tai Tran
10:54 PM To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: Cannot delete persisted object which is not in current session On Jun 30, 2008, at 4:37 AM, Tai Tran wrote: # Create a new Foo object, then save it to the database db_session = Session() f = Foo('001

[sqlalchemy] Re: Cannot delete persisted object which is not in current session

2008-07-01 Thread King Simon-NFHD78
Tai Tran wrote: [snip] class PC(object): ... def destroySelf(self): db_session = Session() ... for port in self.ports: port.destroySelf() ... db_session.delete(self) ... class Port(object): ...

[sqlalchemy] Re: Cannot delete persisted object which is not in current session

2008-07-01 Thread Michael Bayer
On Jun 30, 2008, at 11:27 PM, Tai Tran wrote: I'm using contextual/thread-local sessions, in the last statement db_session.delete(self) of Port.destroySelf(), I always get the same traceback as I tried to demonstrate in the last port: sqlalchemy.exceptions.InvalidRequestError: Instance

[sqlalchemy] Re: Cannot delete persisted object which is not in current session

2008-07-01 Thread Tai Tran
King Simon wrote: The 'object_session' function returns the session that an object is currently associated with. I would have thought that you could write your destroySelf method as: def destroySelf(self): db_session = object_session(self) db_session.delete(self) I have tried using

[sqlalchemy] Re: Cannot delete persisted object which is not in current session

2008-06-30 Thread Michael Bayer
On Jun 30, 2008, at 4:37 AM, Tai Tran wrote: # Create a new Foo object, then save it to the database db_session = Session() f = Foo('001') db_session.save(f) db_session.commit() # Try deleting Foo object created above with a new, different session db_session2 =