# sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: Circular dependency detected.

- **ID:** `python/sqlalchemy-circular-dependency`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Circular relationships between models without proper back_populates or use of lazy='dynamic'.

## Version Compatibility

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

## Workarounds

1. **Use back_populates correctly.** (95% success)
   ```
   class Parent(Base):
    children = relationship('Child', back_populates='parent')
class Child(Base):
    parent_id = Column(ForeignKey('parents.id'))
    parent = relationship('Parent', back_populates='children')
   ```
2. **Use lazy='dynamic' on one side.** (90% success)
   ```
   children = relationship('Child', back_populates='parent', lazy='dynamic')
   ```

## Dead Ends

- **Removing one relationship entirely.** — Loses necessary data access patterns. (50% fail)
- **Setting both relationships to lazy='noload'.** — Prevents loading but may break application logic. (70% fail)
