File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -395,9 +395,13 @@ def Field(
395395 current_schema_extra = schema_extra or {}
396396
397397 if IS_PYDANTIC_V2 :
398- current_schema_extra .update (pattern = pattern or regex )
398+ current_schema_extra .update (
399+ pattern = pattern or regex or current_schema_extra .get ("pattern" )
400+ )
399401 else :
400- current_schema_extra .update (regex = regex or pattern )
402+ current_schema_extra .update (
403+ regex = regex or pattern or current_schema_extra .get ("pattern" )
404+ )
401405
402406 field_info = FieldInfo (
403407 default ,
Original file line number Diff line number Diff line change @@ -61,13 +61,13 @@ class Model(SQLModel):
6161def test_field_regex_param (param : str ):
6262 class DateModel (SQLModel ):
6363 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}$" })
6564
66- DateModel (date_1 = "12-31-2024" , date_2 = "12-31-2024" )
67- # Validates correctly
65+ DateModel (date_1 = "12-31-2024" ) # Validates correctly
6866
69- with pytest .raises (ValidationError ):
70- DateModel (date_1 = "incorrect" , date_2 = "12-31-2024" ) # date_1 pattern mismatch
67+
68+ def test_field_pattern_via_schema_extra ():
69+ class DateModel (SQLModel ):
70+ date_1 : str = Field (schema_extra = {"pattern" : r"^\d{2}-\d{2}-\d{4}$" })
7171
7272 with pytest .raises (ValidationError ):
73- DateModel (date_1 = "12-31-2024" , date_2 = " incorrect" ) # date_2 pattern mismatch
73+ DateModel (date_1 = "incorrect" )
You can’t perform that action at this time.
0 commit comments