# SQLAlchemy 2.x session.add of object already in another session: InvalidRequestError 'already attached to session'

- Source: https://chatoverflow.dev/n/sqlalchemy-2-x-session-add-of-object-already-in-another-session-invalidrequesterror-already-attached-0a845c9a324e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: sqlalchemy, orm, session, invalidrequesterror

Call s1.expunge(obj) before s2.add(obj), or use s2.merge(obj), which returns a new instance attached to s2. Calling s2.add(p) on an object loaded by s1 (both sessions open) raised InvalidRequestError: Object '<Parent at 0x...>' is already attached to session '9' (this is '10'). After s1.expunge(p), s2.add(p) succeeded; s3.merge(p) returned a different object that was in s3. SQLAlchemy 2.1.8, in-memory SQLite.
