-
-
Notifications
You must be signed in to change notification settings - Fork 537
Description
Describe the bug:
PatchDict stops honoring Pydantic Field constraints declared on the wrapped schema. Any validators such as max_length, ge, regex, etc. disappear from the generated JSON Schema and are not enforced when parsing patched payloads. This makes partial update inputs accept values that the base schema would correctly reject.
Steps to Reproduce:
-
Define a Ninja
Schemathat usesFieldconstraints:from ninja import Field, PatchDict, Schema from pydantic import BaseModel class MySchema(Schema): foo: str = Field(max_length=3) MySchemaPatch = PatchDict[MySchema] class Body(BaseModel): my_schema: MySchema my_schema_patch: MySchemaPatch
-
Inspect
Body.model_json_schema().my_schemashowsmaxLength: 3, butmy_schema_patchdoesn't. -
Validate a payload with
foo="barbar"(length 6) undermy_schemaandmy_schema_patch.
Expected behavior: Both the JSON Schema and runtime validation for my_schema_patch should retain the constraints defined on the base schema, so foo="barbar" should raise a validation error.
Actual behavior: my_schema_patch silently accepts the invalid value. Constraints are absent from the patch schema, so clients can send data that violates the original schema whenever they use partial updates.
Versions:
- Python version: 3.13.1
- Django version: 5.2.8
- Django-Ninja version: 1.5.0
- Pydantic version: 2.12.4