# pydantic_core._pydantic_core.ValidationError: 1 个验证错误，检测到循环引用递归错误 [类型=recursion_loop]

- **ID:** `python/pydantic-recursion-loop-detected`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

输入数据包含循环引用（例如对象引用自身），Pydantic 在验证递归模型时检测到该循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   def strip_parent(node):
    node.pop('parent', None)
    for c in node.get('children', []):
        strip_parent(c)
    return node
Node.model_validate(strip_parent(data))
   ```
2. **** (80% 成功率)
   ```
   from pydantic import BaseModel

class Node(BaseModel):
    name: str
    children: list['Node'] = []

Node.model_rebuild()  # avoid modeling parent back-references
   ```

## 无效尝试

- **** — The cycle is in the data itself, not stack depth. It will still be detected and may crash the interpreter. (85% 失败率)
- **** — Loses the schema definition and breaks legitimate nested validation for non-cyclic inputs. (70% 失败率)
