# AttributeError: 'User' object has no attribute 'addresses'

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

## Root Cause

Relationship not defined or not loaded due to lazy loading outside session.

## Version Compatibility

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

## Workarounds

1. **Define relationship in model class.** (95% success)
   ```
   class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    addresses = relationship('Address', back_populates='user')
   ```
2. **Eagerly load relationship in query.** (90% success)
   ```
   user = session.query(User).options(joinedload(User.addresses)).first()
print(user.addresses)  # Now available
   ```

## Dead Ends

- **Adding the attribute manually to the class.** — Relationship must be defined via SQLAlchemy ORM; manual attribute breaks mapping. (90% fail)
- **Using getattr with default but still accessing lazy attribute.** — Underlying relationship still not loaded; returns None incorrectly. (70% fail)
