The NotImplementedError fallback is only hit by older Pydantic versions in the test matrix. Added # pragma: no cover so the 100% coverage requirement passes for modern environments.
Added a fallback to json.loads when Pydantic's validate_json throws NotImplementedError. This fixes compatibility issues with older Pydantic versions in CI testing for endpoints utilizing arbitrary types (like Missing). Also ran Ruff to fix formatting and linting issues reported by pre-commit hooks.
Remove the 'await request.json()' call which was inadvertently left in the routing path. This ensures that the body bytes are passed directly to Pydantic's validate_json via FastAPIOptimizedJsonBytes, bypassing unnecessary Python dict allocations entirely.
Moving the import of pydantic.v1 and the warnings filter to the module level avoids executing them on every single object serialization in jsonable_encoder, significantly boosting performance for Pydantic v1 backward compatibility checks.
Group validation of multiple parameters (query, path, headers, cookies) into a single Pydantic call using a dynamically generated BaseModel.
- Introduce get_grouped_adapter with lru_cache to cache synthetic models
- Replace individual parameter validation loop with validate_python
- Reconstruct FastAPI-compatible ValidationError structure to ensure complete backwards compatibility for error locations and input fields.
This commit introduces a fast-path for the jsonable_encoder and directly uses TypeAdapter(Any).dump_json() and dump_python() in astapi.routing and astapi.encoders. By leveraging the Rust-based pydantic-core directly, serialization overhead for complex types is significantly reduced.
- Use TypeAdapter(Any).dump_json() in _serialize_data and _serialize_sse_item
- Add fast-path to jsonable_encoder to use TypeAdapter(Any).dump_python(mode='json')
- Update test_sse_events_with_fields to account for minified JSON output of Pydantic v2
Fix "to to" and "that that" word duplications in security module docstrings,
and "be be" in test data string.
Co-authored-by: ahsan.sheraz <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>