{
  "id": "python/sqlalchemy-stale-data-read",
  "signature": "sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'users' expected to match 1 row(s); 0 found",
  "signature_zh": "sqlalchemy.orm.exc.StaleDataError: 表 'users' 上的 UPDATE 语句预期匹配 1 行；实际找到 0 行",
  "regex": "sqlalchemy\\.orm\\.exc\\.StaleDataError:\\ UPDATE\\ statement\\ on\\ table\\ 'users'\\ expected\\ to\\ match\\ 1\\ row\\(s\\);\\ 0\\ found",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "An optimistic concurrency check failed because the row was modified or deleted by another transaction since it was read.",
  "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": "Ignoring the error and retrying the update",
      "why_fails": "The row may have been deleted, so the update will still fail.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disabling versioning in the model",
      "why_fails": "This removes concurrency protection, leading to potential data corruption.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Re-query the object before updating",
      "success_rate": 0.95,
      "how": "user = session.query(User).get(user_id)\nif user:\n    user.name = 'New Name'\n    session.commit()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use session.refresh() to reload the object",
      "success_rate": 0.9,
      "how": "session.refresh(user)\nuser.name = 'New Name'\nsession.commit()",
      "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-12-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}