{
  "id": "python/sqlalchemy-detached-instance-error",
  "signature": "sqlalchemy.orm.exc.DetachedInstanceError: Instance <User at 0x...> is not bound to a Session",
  "signature_zh": "sqlalchemy.orm.exc.DetachedInstanceError: 实例 <User at 0x...> 未绑定到任何会话",
  "regex": "sqlalchemy\\.orm\\.exc\\.DetachedInstanceError:\\ Instance\\ <User\\ at\\ 0x\\.\\.\\.>\\ is\\ not\\ bound\\ to\\ a\\ Session",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to access or modify an ORM instance that has been detached from its session, usually after session.close() or session.expunge_all().",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试访问或修改一个已与会话分离的ORM实例，通常是在调用 session.close() 或 session.expunge_all() 之后。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Calling session.add() on the detached instance",
      "why_fails": "The instance is not in a pending state; it needs to be merged first.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Reopening the session and reusing the same instance",
      "why_fails": "The instance's state is stale; you need to merge or refresh it.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use session.merge() to reattach the instance",
      "success_rate": 0.95,
      "how": "merged_user = session.merge(detached_user)\nprint(merged_user.name)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refresh the instance with session.refresh() after reattaching",
      "success_rate": 0.85,
      "how": "session.add(detached_user)\nsession.refresh(detached_user)",
      "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": "2024-04-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}