MCPcopy Index your code
hub / github.com/fastapi/sqlmodel / test_validation_pydantic_v2

Function test_validation_pydantic_v2

tests/test_validation.py:6–31  ·  view source on GitHub ↗

Test validation of implicit and explicit None values. # For consistency with pydantic, validators are not to be called on # arguments that are not explicitly provided. https://github.com/tiangolo/sqlmodel/issues/230 https://github.com/samuelcolvin/pydantic/issues/1223

(clear_sqlmodel)

Source from the content-addressed store, hash-verified

4
5
6def test_validation_pydantic_v2(clear_sqlmodel):
7 """Test validation of implicit and explicit None values.
8
9 # For consistency with pydantic, validators are not to be called on
10 # arguments that are not explicitly provided.
11
12 https://github.com/tiangolo/sqlmodel/issues/230
13 https://github.com/samuelcolvin/pydantic/issues/1223
14
15 """
16 from pydantic import field_validator
17
18 class Hero(SQLModel):
19 name: str | None = None
20 secret_name: str | None = None
21 age: int | None = None
22
23 @field_validator("name", "secret_name", "age")
24 def reject_none(cls, v):
25 assert v is not None
26 return v
27
28 Hero.model_validate({"age": 25})
29
30 with pytest.raises(ValidationError):
31 Hero.model_validate({"name": None, "age": 25})

Callers

nothing calls this directly

Calls 1

model_validateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…