Skip to content

Commit 2420797

Browse files
committed
WIP - Add failing TypeAdapter test
1 parent 6b4c652 commit 2420797

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/test_validation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def reject_none(cls, v):
7171
@needs_pydanticv2
7272
def test_validation_strict_mode(clear_sqlmodel):
7373
"""Test validation of fields in strict mode from python and json."""
74+
from pydantic import TypeAdapter
7475

7576
class Hero(SQLModel):
7677
id: Optional[int] = None
@@ -85,6 +86,9 @@ class Hero(SQLModel):
8586
uuid_str = str(uuid_obj)
8687

8788
Hero.model_validate({"id": 1, "birth_date": date_obj, "uuid": uuid_obj})
89+
TypeAdapter(Hero).validate_python(
90+
{"id": 1, "birth_date": date_obj, "uuid": uuid_obj}
91+
)
8892
# Check that python validation requires strict types
8993
with pytest.raises(ValidationError):
9094
Hero.model_validate({"id": "1"})
@@ -97,5 +101,8 @@ class Hero(SQLModel):
97101
Hero.model_validate_json(
98102
json.dumps({"id": 1, "birth_date": date_str, "uuid": uuid_str})
99103
)
104+
TypeAdapter(Hero).validate_json(
105+
json.dumps({"id": 1, "birth_date": date_str, "uuid": uuid_str})
106+
)
100107
with pytest.raises(ValidationError):
101108
Hero.model_validate_json(json.dumps({"id": "1"}))

0 commit comments

Comments
 (0)