File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import json
99{ {#vendorExtensions.x-py-model-imports} }
1010{ {{.} }}
1111{ {/vendorExtensions.x-py-model-imports} }
12+ from pydantic import field_validator
1213from typing import Optional, Set
1314from typing_extensions import Self
1415
@@ -91,6 +92,21 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
9192 { {/isContainer} }
9293 return value
9394 { {/isEnum} }
95+
96+ { {! BEGIN OF WORKAROUND - YEAR 0 ISSUE - see } }
97+ { {#isDateTime} }
98+ @field_validator('{ {{name} }}', mode='before')
99+ def { {{name} }}_change_year_zero_to_one(cls, value):
100+ """Workaround which prevents year 0 issue"""
101+ if isinstance(value, str):
102+ # Check for year "0000" at the beginning of the string
103+ # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
104+ if value.startswith("0000-01-01T") and re.match(r'^\d{ 4} -\d{ 2} -\d{ 2} T\d{ 2} :\d{ 2} :\d{ 2} (\+\d{ 2} :\d{ 2} |Z)$', value):
105+ # Workaround: Replace "0000" with "0001"
106+ return "0001" + value[4:] # Take "0001" and append the rest of the string
107+ return value
108+ { {/isDateTime} }
109+ { {! END OF WORKAROUND - YEAR 0 ISSUE } }
94110{ {/vars} }
95111
96112 model_config = ConfigDict(
You can’t perform that action at this time.
0 commit comments