{
  "id": "python/sqlalchemy-orm-exc-detached-instance-merge-conflict",
  "signature": "sqlalchemy.orm.exc.DetachedInstanceError: Instance <User at 0x...> is detached; merge() cannot proceed because the session already has a different instance with the same primary key",
  "signature_zh": "实例 <User at 0x...> 是分离的；merge() 无法进行，因为会话已有一个具有相同主键的不同实例",
  "regex": "sqlalchemy\\.orm\\.exc\\.DetachedInstanceError:\\ Instance\\ <User\\ at\\ 0x\\.\\.\\.>\\ is\\ detached;\\ merge\\(\\)\\ cannot\\ proceed\\ because\\ the\\ session\\ already\\ has\\ a\\ different\\ instance\\ with\\ the\\ same\\ primary\\ key",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to merge a detached instance when the session already tracks another instance with the same primary key, causing identity conflict.",
  "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": "Deleting existing instance",
      "why_fails": "",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using add() instead",
      "why_fails": "",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Expunge existing instance first",
      "success_rate": 0.85,
      "how": "Expunge the existing instance from session before merge: session.expunge(existing_instance); session.merge(detached_instance)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Merge with clean session",
      "success_rate": 0.9,
      "how": "Use session.merge() with a new instance that does not conflict, or ensure the session is clean before merging.",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-09-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}