Skip to content

Partial t model recursion#1996

Closed
jxnl wants to merge 2 commits intomainfrom
cursor/partial-t-model-recursion-36dc
Closed

Partial t model recursion#1996
jxnl wants to merge 2 commits intomainfrom
cursor/partial-t-model-recursion-36dc

Conversation

@jxnl
Copy link
Collaborator

@jxnl jxnl commented Jan 13, 2026

fix: Stop Partial[T] from infinite recursion on self-referential models

Describe your changes

This change prevents Partial[T] from entering infinite recursion when processing self-referential Pydantic models.

The solution involves:

  • Tracking models currently being processed to detect recursive fields.
  • Using ForwardRef for recursive fields to break the immediate cycle.
  • Rebuilding the generated Partial model with a namespace that resolves these forward references, ensuring the schema remains finite.
  • Added a new test case (test_partial_handles_self_referential_models) to validate the fix.

Issue ticket number and link

#1995

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • If it is a core feature, I have added documentation.

Slack Thread

Open in Cursor Open in Web

Guard Partial[T] creation against infinite recursion by tracking in-progress models and resolving forward refs. Add a regression test and changelog entry for the fix.
@cursor
Copy link

cursor bot commented Jan 13, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions github-actions bot added bug Something isn't working enhancement New feature or request python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 13, 2026
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 13, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor f24cbe9 Commit Preview URL

Branch Preview URL
Jan 13 2026, 02:43 PM

Exercise Partial[TreeNode] via model_from_chunks to prove recursive models work end-to-end instead of only through direct validation.
@jxnl jxnl closed this Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants