{
  "id": "python/sqlalchemy-lazy-load-error",
  "signature": "sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <User at 0x...> is not bound to a Session; lazy load operation of attribute 'addresses' cannot proceed",
  "signature_zh": "sqlalchemy.orm.exc.DetachedInstanceError: 父实例 <User at 0x...> 未绑定到会话；属性 'addresses' 的延迟加载操作无法进行",
  "regex": "sqlalchemy\\.orm\\.exc\\.DetachedInstanceError:\\ Parent\\ instance\\ <User\\ at\\ 0x\\.\\.\\.>\\ is\\ not\\ bound\\ to\\ a\\ Session;\\ lazy\\ load\\ operation\\ of\\ attribute\\ 'addresses'\\ cannot\\ proceed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to access a lazy-loaded relationship on a detached instance, which requires an active session.",
  "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": "Re-opening the session and reusing the same instance",
      "why_fails": "The instance is still detached; you need to merge or reattach it.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Calling session.close() before accessing the attribute",
      "why_fails": "Closing the session makes the instance detached.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Eagerly load the relationship before detaching",
      "success_rate": 0.95,
      "how": "user = session.query(User).options(joinedload(User.addresses)).first()\nsession.close()\nprint(user.addresses)  # Works because addresses are already loaded",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use session.merge() to reattach the instance",
      "success_rate": 0.9,
      "how": "user = session.merge(detached_user)\nprint(user.addresses)",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-05-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}