Skip to content

Commit 01b3954

Browse files
committed
Add warning when pattern is passed via schema_extra
1 parent 57c6c53 commit 01b3954

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sqlmodel/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ def Field(
400400
DeprecationWarning,
401401
stacklevel=2,
402402
)
403+
if "pattern" in current_schema_extra:
404+
warnings.warn(
405+
"Pass `pattern` parameter directly to Field instead of passing it via `schema_extra`",
406+
DeprecationWarning,
407+
stacklevel=2,
408+
)
403409

404410
# Extract possible alias settings from schema_extra so we can control precedence
405411
schema_validation_alias = current_schema_extra.pop("validation_alias", None)

tests/test_pydantic/test_field.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ class DateModel(SQLModel):
7979

8080

8181
def test_field_pattern_via_schema_extra():
82-
class DateModel(SQLModel):
83-
date_1: str = Field(schema_extra={"pattern": r"^\d{2}-\d{2}-\d{4}$"})
82+
with pytest.warns(
83+
DeprecationWarning,
84+
match="Pass `pattern` parameter directly to Field instead of passing it via `schema_extra`",
85+
):
86+
87+
class DateModel(SQLModel):
88+
date_1: str = Field(schema_extra={"pattern": r"^\d{2}-\d{2}-\d{4}$"})
8489

8590
with pytest.raises(ValidationError):
8691
DateModel(date_1="incorrect")

0 commit comments

Comments
 (0)