{
  "id": "python/sqlalchemy-detached-instance-session-closed",
  "signature": "sqlalchemy.orm.exc.DetachedInstanceError: Instance is not bound to a Session; attribute refresh operation cannot proceed",
  "signature_zh": "实例未绑定到会话；无法执行属性刷新操作",
  "regex": "sqlalchemy\\.orm\\.exc\\.DetachedInstanceError:\\ Instance\\ is\\ not\\ bound\\ to\\ a\\ Session;\\ attribute\\ refresh\\ operation\\ cannot\\ proceed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to access or refresh attributes of an ORM instance after its originating session has been closed or committed, leaving the instance in a detached state.",
  "root_cause_type": "generic",
  "root_cause_zh": "在原始会话已关闭或提交后尝试访问或刷新 ORM 实例的属性，导致实例处于分离状态。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Re-querying the object with session.query() without merging",
      "why_fails": "",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Enabling autocommit on the session",
      "why_fails": "",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Merge the detached instance back into the session",
      "success_rate": 0.85,
      "how": "Use session.merge() to re-attach the detached instance to a new session before accessing attributes.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refresh the instance before session closure",
      "success_rate": 0.9,
      "how": "Ensure the session remains open and use session.refresh() before closing, or load needed attributes eagerly.",
      "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": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}