# sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[User], expression 'Post' failed to locate a name ('Post'). If this is a class name, consider adding this relationship() to the class after both dependent classes have been defined.

- **ID:** `python/sqlalchemy-circular-import-models`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Circular imports between model modules cause one model class to be undefined when the other's mapper is configured.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use string-based relationship references: class User(Base): posts = relationship('Post', back_populates='user') - and ensure Post is defined later in the same module or imported lazily.
   ```
2. **** (85% success)
   ```
   Use the 'late-binding' pattern: define relationships in a separate configure_mappers() call after all models are imported: from sqlalchemy.orm import configure_mappers; configure_mappers()
   ```

## Dead Ends

- **** — Top-level imports still trigger the same circular dependency; the classes are not yet defined at import time. (90% fail)
- **** — If the __init__.py imports both modules, it still hits the circular reference during module initialization. (80% fail)
