Skip to content

fix: Warn incomplete FieldInfo ForwardRefs#855

Open
nullwiz wants to merge 3 commits into
pydantic:mainfrom
nullwiz:warn-incomplete-fieldinfo-forwardrefs
Open

fix: Warn incomplete FieldInfo ForwardRefs#855
nullwiz wants to merge 3 commits into
pydantic:mainfrom
nullwiz:warn-incomplete-fieldinfo-forwardrefs

Conversation

@nullwiz
Copy link
Copy Markdown

@nullwiz nullwiz commented May 5, 2026

Summary

When a FieldInfo contains an unresolved forward reference, Pydantic marks it as incomplete (FieldInfo._complete is False). Settings sources (env, dotenv, CLI, secrets, defaults, init) that read these fields can silently fail to apply nested overrides.

This adds _warn_if_field_incomplete() to PydanticBaseSettingsSource, called from all source classes (let me know if something is missing here) that iterate over model_fields.

Includes dedup (keyed by id(field)) so the same FieldInfo isn't warned twice. For example, DotEnvSettingsSource reads fields both in super().__call__() and again afterwards.

The warning message includes the model_rebuild() remediation hint as suggested in pydantic/pydantic#11453.

Test plan

  • Added test_warn_on_incomplete_field asserting the warning does indeed fire and the dedup works correctly
  • All 463 tests pass

Related issues

Fixes #775

@hramezani hramezani requested a review from Viicos May 5, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ForwardRef in nested BaseModel breaks env_nested_delimiter overrides (regression vs 2.10.x)

1 participant