# pydantic.errors.PydanticUndefinedAnnotation: `Node` is not defined

- **ID:** `python/pydantic-recursion-error-self-referencing`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A self-referencing model uses a forward reference that Pydantic cannot resolve because the class name is not yet in scope during schema building.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   from typing import Optional
class Node(BaseModel):
    value: int
    child: Optional["Node"] = None
Node.model_rebuild()
   ```
2. **** (90% success)
   ```
   class Node(BaseModel):
    model_config = ConfigDict(defer_build=True)
    child: Optional["Node"] = None
   ```

## Dead Ends

- **** — Loses recursive validation; nested children are not validated and errors propagate silently. (70% fail)
- **** — Postpones evaluation but Pydantic still needs model_rebuild() to resolve the reference at runtime. (60% fail)
- **** — Causes duplicate class definitions and Pydantic still cannot resolve the forward ref cleanly. (90% fail)
