Skip to content

Commit

Permalink
Merge PR #375 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Sep 19, 2023
2 parents b6d8435 + 7ff7edd commit f22a1ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
3 changes: 0 additions & 3 deletions extendable_fastapi/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class StrictExtendableBaseModel(
revalidate_instances="always",
validate_assignment=True,
extra="forbid",
strict=True,
):
"""
An ExtendableBaseModel with strict validation.
Expand All @@ -24,6 +23,4 @@ class StrictExtendableBaseModel(
(default is "never")
* validate_assignment=True: revalidate the model when the data is changed (default is False)
* extra="forbid": Forbid any extra attributes (default is "ignore")
* strict=True: raise an error if a value's type does not match the field's type
annotation (default is False; Pydantic attempts to coerce values to the correct type)
"""
13 changes: 4 additions & 9 deletions extendable_fastapi/tests/test_strict_extendable_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ def test_StrictModel_extra_forbidden(self):
with self.assertRaises(ValidationError):
self.StrictModel(x=1, z=3, d=None)

def test_Model_strict_false(self):
# Coerce str->date is allowed
m = self.Model(x=1, d=None)
def test_StrictModel_strict_false(self):
# Coerce str->date is allowed to enable coercion from JSON
# by FastAPI
m = self.StrictModel(x=1, d=None)
m.d = "2023-01-01"
self.assertTrue(m.model_validate(m))

def test_StrictModel_strict_true(self):
# Coerce str->date is forbidden
m = self.StrictModel(x=1, d=None)
with self.assertRaises(ValidationError):
m.d = "2023-01-01"

0 comments on commit f22a1ac

Please sign in to comment.