Skip to content

[pyrefly] Respect RootModel field defaults#4279

Open
ytausch wants to merge 1 commit into
facebook:mainfrom
ytausch:yt/fix-root-model-field-default
Open

[pyrefly] Respect RootModel field defaults#4279
ytausch wants to merge 1 commit into
facebook:mainfrom
ytausch:yt/fix-root-model-field-default

Conversation

@ytausch

@ytausch ytausch commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Pyrefly RootModel constructor synthesis bypassed the field metadata used by other Pydantic models, so root fields with default or default_factory were still treated as required.

The fix checks if the root dataclass member has a default set.

Fixes #4278

Test Plan

Added a test case in pyrefly/lib/test/pydantic/root_model.rs.

AI Note

I used GPT-5.6 Sol in helping me preparing this PR. I reviewed and reworked it manually.

@meta-cla

meta-cla Bot commented Jul 24, 2026

Copy link
Copy Markdown

Hi @ytausch!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

RootModel constructor synthesis bypassed the field metadata used by other Pydantic models, so root fields with defaults were still treated as required.\n\nUse the normalized dataclass field keywords when choosing root parameter requiredness. This handles both default and default_factory while leaving root fields without defaults required.
@ytausch
ytausch force-pushed the yt/fix-root-model-field-default branch from 1992bb4 to e02d63c Compare July 24, 2026 11:38
@meta-cla meta-cla Bot added the cla signed label Jul 24, 2026
@github-actions github-actions Bot added size/s and removed size/s labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pydantic RootModel root default not respected

1 participant