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