# 查询已定义标签，但正在迭代结果。请使用 .all() 或 .first()

- **ID:** `python/sqlalchemy-query-corrupted-during-iteration`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试迭代已配置列标签的 Query 对象，不允许直接迭代。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

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

## 无效尝试

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