{
  "id": "python/pydantic-recursion-loop-detected",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Node\nchildren.0.parent\n  Recursion error - cyclic reference detected [type=recursion_loop]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 1 个验证错误，检测到循环引用递归错误 [类型=recursion_loop]",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Node\\\nchildren\\.0\\.parent\\\n\\ \\ Recursion\\ error\\ \\-\\ cyclic\\ reference\\ detected\\ \\[type=recursion_loop\\]",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The input data contains a cyclic reference (e.g. an object referencing itself), which Pydantic detects while validating a recursive model.",
  "root_cause_type": "generic",
  "root_cause_zh": "输入数据包含循环引用（例如对象引用自身），Pydantic 在验证递归模型时检测到该循环。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The cycle is in the data itself, not stack depth. It will still be detected and may crash the interpreter.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses the schema definition and breaks legitimate nested validation for non-cyclic inputs.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def strip_parent(node):\n    node.pop('parent', None)\n    for c in node.get('children', []):\n        strip_parent(c)\n    return node\nNode.model_validate(strip_parent(data))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "from pydantic import BaseModel\n\nclass Node(BaseModel):\n    name: str\n    children: list['Node'] = []\n\nNode.model_rebuild()  # avoid modeling parent back-references",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-08-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}