{
  "id": "python/sqlalchemy-lazy-load-race-condition",
  "signature": "sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <User at 0x7f...> is not bound to a Session; lazy load operation of attribute 'orders' cannot proceed",
  "signature_zh": "父实例 <User at 0x7f...> 未绑定到会话；属性 'orders' 的懒加载操作无法继续",
  "regex": "sqlalchemy\\.orm\\.exc\\.DetachedInstanceError:\\ Parent\\ instance\\ <User\\ at\\ 0x7f\\.\\.\\.>\\ is\\ not\\ bound\\ to\\ a\\ Session;\\ lazy\\ load\\ operation\\ of\\ attribute\\ 'orders'\\ cannot\\ proceed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Accessing a lazy-loaded relationship after the session has been closed or the object has been detached.",
  "root_cause_type": "generic",
  "root_cause_zh": "在会话关闭或对象被分离后访问懒加载关系。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The object remains detached; lazy load still fails unless refresh is performed.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same issue; closing session detaches objects.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from sqlalchemy.orm import joinedload\nuser = session.query(User).options(joinedload(User.orders)).first()\n# Now access user.orders after session close works",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "new_session = Session()\nnew_session.add(user)\nnew_session.refresh(user)\norders = user.orders  # now works",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}