File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ def reject_none(cls, v):
7171@needs_pydanticv2
7272def 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" }))
You can’t perform that action at this time.
0 commit comments