Re: [sqlalchemy] checking if some object with the given id is in a session

2011-09-20 Thread Michael Bayer
you can check for a given identity in the session using the identity key functions: from sqlalchemy.orm.util import identity_key key= identity_key(MyClass, someid) object_already_in_session = key in session.identity_map but usually people use session.merge(object) instead of session.add() to

[sqlalchemy] checking if some object with the given id is in a session

2011-09-19 Thread Eduardo
Hi, I create a certain number of objects in a loop, I check if each of the objects is already stored in the session and if it is not I add it to the session. session = Session() for item in items: item1=create_item() if not item1 in session: session.add(item1) session.commit() The