There was an error while loading. Please reload this page.
1 parent 2d6bb87 commit 5de3c0bCopy full SHA for 5de3c0b
tests/test_pydantic/test_field.py
@@ -55,3 +55,17 @@ class Model(SQLModel):
55
56
instance = Model(id=123, foo="bar")
57
assert "foo=" not in repr(instance)
58
+
59
60
+@pytest.mark.parametrize("param", ["regex", "pattern"])
61
+def test_field_regex_param(param: str):
62
+ class DateModel(SQLModel):
63
+ date_1: str = Field(**{param: r"^\d{2}-\d{2}-\d{4}$"})
64
+ date_2: str = Field(schema_extra={param: r"^\d{2}-\d{2}-\d{4}$"})
65
66
+ DateModel(date_1="12-31-2024", date_2="12-31-2024")
67
+ # Validates correctly
68
69
+ with pytest.raises(ValidationError):
70
+ DateModel(date_1="2024-12-31", date_2="2024-12-31")
71
+ # This should raise a ValueError due to regex mismatch
0 commit comments