Commit Graph

1 Commits

Author SHA1 Message Date
Adarsh Bennur 349c3667cf Fix: Preserve model_fields_set for Form models (issue #13399)
When using Form() with Pydantic models, FastAPI was preloading default
values and passing them to Pydantic, causing all fields to appear in
model_fields_set even when not provided. This also caused validation
to be enforced on unprovided defaults.

Changes:
- Modified _get_multidict_value() to check if values is FormData
- For FormData, return None for unprovided fields instead of defaults
- This lets Pydantic handle defaults properly and preserve fields_set
- Updated test expectation in test_forms_single_model.py
- Added comprehensive test suite in test_forms_fields_set.py

The fix ensures Form models behave consistently with JSON body models
regarding field tracking and validation.

Closes #13399
2025-12-19 18:38:39 +05:30