Skip to content

Commit 9f9a4fb

Browse files
committed
test(tests): 🚨 Update existing tests to match new behaviour of JSON schema extra
1 parent 8ec6930 commit 9f9a4fb

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

‎tests/test_partial_without_mixin.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99

1010
def _field_is_required(model: Union[type[pydantic.BaseModel], pydantic.BaseModel], field_name: str) -> bool:
1111
"""Check if a field is required on a pydantic V2 model."""
12-
json_required = (
13-
model.model_fields[field_name].json_schema_extra is not None
14-
and model.model_fields[field_name].json_schema_extra.get("required", False)
15-
)
16-
return model.model_fields[field_name].is_required() or json_required
12+
13+
return model.model_fields[field_name].is_required()
1714

1815

1916
class Something(pydantic.BaseModel):
2017
name: str
2118
age: int
2219
already_optional: None = None
23-
already_required: int = pydantic.Field(default=1, json_schema_extra={"required": True})
20+
already_required: int = pydantic.Field(default=1)
2421

2522

2623
class SomethingWithMixin(PartialModelMixin, pydantic.BaseModel):
@@ -62,12 +59,6 @@ def test_partial_model_will_be_the_same_on_mixin():
6259

6360
assert SomethingWithMixinPartial1 is SomethingWithMixinPartial2
6461

65-
def test_pydantic_v2_partial_model_will_override_json_required():
66-
SomethingPartial = create_partial_model(Something)
67-
assert _field_is_required(SomethingPartial, "already_required") is False
68-
schema = SomethingPartial.model_json_schema()
69-
assert schema["properties"]["already_required"]["nullable"] is True
70-
assert schema["properties"]["already_required"]["required"] is False
7162

7263
def test_partial_class_name_can_be_overridden():
7364
SomethingPartial = create_partial_model(Something, "name")

0 commit comments

Comments
 (0)