{
  "id": "python/sqlalchemy-orm-exc-concurrent-modification-error",
  "signature": "sqlalchemy.orm.exc.ConcurrentModificationError: Object '<User at 0x...>' is being merged into a Session but the same instance is already present",
  "signature_zh": "对象 '<User at 0x...>' 正在被合并到会话中，但相同的实例已存在",
  "regex": "sqlalchemy\\.orm\\.exc\\.ConcurrentModificationError:\\ Object\\ '<User\\ at\\ 0x\\.\\.\\.>'\\ is\\ being\\ merged\\ into\\ a\\ Session\\ but\\ the\\ same\\ instance\\ is\\ already\\ present",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to merge an ORM instance that is already tracked by the same session, causing a conflict.",
  "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": "Using add() instead of merge()",
      "why_fails": "",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Expunging the instance first",
      "why_fails": "",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check session identity map",
      "success_rate": 0.8,
      "how": "Check if the instance is already in the session using session.is_modified() or track identities manually before merging.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Merge with fresh instance",
      "success_rate": 0.9,
      "how": "Use session.merge() with a new instance that has the same primary key, ensuring the session does not already contain it.",
      "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": "2024-11-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}