{
  "id": "python/sqlalchemy-query-corrupted-during-iteration",
  "signature": "sqlalchemy.exc.InvalidRequestError: Query has been defined with a label, but the result is being iterated over. Use .all() or .first()",
  "signature_zh": "查询已定义标签，但正在迭代结果。请使用 .all() 或 .first()",
  "regex": "sqlalchemy\\.exc\\.InvalidRequestError:\\ Query\\ has\\ been\\ defined\\ with\\ a\\ label,\\ but\\ the\\ result\\ is\\ being\\ iterated\\ over\\.\\ Use\\ \\.all\\(\\)\\ or\\ \\.first\\(\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Trying to iterate over a Query object that has been configured with a column label, which is not allowed directly.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试迭代已配置列标签的 Query 对象，不允许直接迭代。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "May still raise the same error because the query is already labeled.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changes the result structure.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 1.0,
      "how": "result = session.query(User.name.label('username')).all()\nfor row in result:\n    print(row.username)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-08-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}