Re: [sqlalchemy] Re: object_session returns None, but state still has session_id

2011-09-22 Thread Ben Ford
Hi Mike, It is an edge case for sure. I'm using SA with eventlet so the session is going out of scope in a green thread. Eventlet does some monkeying (literally) around with threadlocals so I get a different session for each one. However in this case the parent instance to which I'm adding obj

[sqlalchemy] object_session returns None, but state still has session_id

2011-09-21 Thread Ben Ford
Hi Folks, I have the following code: obj = some object created by adding to a parent's collection ses = object_session(obj) if not ses: ses = Session() ses.add(obj) ses.commit() This is giving me InvalidRequestError: saying that the object is attached to a session. When looking into

[sqlalchemy] Re: object_session returns None, but state still has session_id

2011-09-21 Thread Ben Ford
I've now tried a make_transient so my code looks like this: obj = some object created by adding to a parent's collection ses = object_session(obj) if not ses: make_transient(obj) ses = Session() ses.add(obj) ses.commit() I still get the same exception. I guess my other option now is