# sqlalchemy.exc.PendingRollbackError: Can't reconnect until invalid transaction is rolled back.  Please rollback() fully before proceeding

- **ID:** `python/sqlalchemy-missing-session-commit`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A previous SQL operation failed (e.g., constraint violation) but the session was not rolled back. Subsequent operations on the same session trigger this error because the transaction remains in a failed state.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Explicitly rollback the session after any exception: try: session.commit() except: session.rollback() raise
   ```
2. **** (90% success)
   ```
   Use a context manager pattern: with session.begin(): # operations - automatically rolls back on exception
   ```

## Dead Ends

- **** — close() does not reset the transaction state; it only releases connections. The next session usage still carries the failed transaction. (90% fail)
- **** — The error is persistent until rollback is explicitly called; retrying the same failed operation doesn't clear the invalid transaction flag. (100% fail)
