Commit Graph

6 Commits

Author SHA1 Message Date
Adarsh Bennur 34c0142517 Fix test syntax + ruff issues causing CI matrix failures
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-06 23:34:20 +05:30
Adarsh Bennur 3f2e378ff3 Fix: Use typing_extensions.Annotated for Python 3.8 compatibility
Changed import in tests/test_forms_fields_set.py from typing.Annotated
to typing_extensions.Annotated to ensure tests run on Python 3.8.

This fixes the Test / check CI failure and restores coverage to 100%
by allowing the comprehensive coverage tests to execute on all Python
versions in the CI matrix.
2026-02-06 23:31:43 +05:30
Adarsh Bennur ca8b59f52d Fix coverage by adding Query/Header tests to test_forms_fields_set.py
Ensures that _get_multidict_value is fully covered (both FormData and non-FormData paths) to satisfy CI requirements.
2026-02-06 23:31:43 +05:30
Adarsh Bennur 39b4ae0698 Fix: Make fields_set tests compatible with Pydantic v1 and v2
Rewrote test_forms_fields_set.py to work on both Pydantic versions:
- Use PYDANTIC_V2 flag from fastapi._compat
- Use model_fields_set (v2) or __fields_set__ (v1) appropriately
- Removed field_validator which is v2-only
- All tests now run on both versions for full coverage
2026-02-06 23:31:43 +05:30
Adarsh Bennur 3c62970852 Fix: Make test compatible with Pydantic v1 and v2
Add version check to skip test_forms_fields_set.py when Pydantic v1
is installed, since field_validator is a v2-only API.
2026-02-06 23:31:43 +05:30
Adarsh Bennur b82e39d665 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
2026-02-06 23:31:43 +05:30