# sqlalchemy.exc.InvalidRequestError: Query has been defined with a label, but the result is being iterated over. Use .all() or .first()

- **ID:** `python/sqlalchemy-query-corrupted-during-iteration`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Trying to iterate over a Query object that has been configured with a column label, which is not allowed directly.

## Version Compatibility

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

## Workarounds

1. **** (100% success)
   ```
   result = session.query(User.name.label('username')).all()
for row in result:
    print(row.username)
   ```

## Dead Ends

- **** — May still raise the same error because the query is already labeled. (60% fail)
- **** — Changes the result structure. (40% fail)
