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 this I have found: - obj._sa_instance_state.session_id is not in sqlalchemy.orm.session._sessions. - object_session(parent) also returns None - The session_id given in the InvalidRequestError (i.e <session_id> in this part of the message is already attached to session '<session_id>') == parent._sa_instance_state.session_id I'm not that familiar with SA's code, but wondered if it would be possible to check for a Session not being valid? Perhaps when the KeyError is caught in the sqlalchemy.orm.session._state_session function (line 1722 in my version) the state session_id could be set to None - or any other action taken that would make the state look like it didn't have a Session. As for a fix, I guess the best thing to do would be to make_transient(obj) or is there a better way? Thanks, Ben -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/bGDqyB64kZYJ. To post to this group, send email to [email protected]. 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.
