# sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <User at 0x...> is not bound to a Session; lazy load operation of attribute 'addresses' cannot proceed

- **ID:** `python/sqlalchemy-lazy-load-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to access a lazy-loaded relationship on a detached instance, which requires an active session.

## Version Compatibility

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

## Workarounds

1. **Eagerly load the relationship before detaching** (95% success)
   ```
   user = session.query(User).options(joinedload(User.addresses)).first()
session.close()
print(user.addresses)  # Works because addresses are already loaded
   ```
2. **Use session.merge() to reattach the instance** (90% success)
   ```
   user = session.merge(detached_user)
print(user.addresses)
   ```

## Dead Ends

- **Re-opening the session and reusing the same instance** — The instance is still detached; you need to merge or reattach it. (75% fail)
- **Calling session.close() before accessing the attribute** — Closing the session makes the instance detached. (85% fail)
