We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d6bb87 commit 3f99f49Copy full SHA for 3f99f49
tests/test_pydantic/test_field.py
@@ -55,3 +55,18 @@ 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 will raise a ValueError due to regex mismatch
72
+ raise AssertionError("Expected ValidationError for invalid date format")
0 commit comments