# sqlalchemy.orm.exc.ConcurrentModificationError: Object '<User at 0x...>' is being merged into a Session but the same instance is already present

- **ID:** `python/sqlalchemy-orm-exc-concurrent-modification-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to merge an ORM instance that is already tracked by the same session, causing a conflict.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Check session identity map** (80% success)
   ```
   Check if the instance is already in the session using session.is_modified() or track identities manually before merging.
   ```
2. **Merge with fresh instance** (90% success)
   ```
   Use session.merge() with a new instance that has the same primary key, ensuring the session does not already contain it.
   ```

## Dead Ends

- **Using add() instead of merge()** —  (70% fail)
- **Expunging the instance first** —  (50% fail)
