File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-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,22 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
9192 { {/isContainer} }
9293 return value
9394 { {/isEnum} }
95+
96+ { {! BEGIN OF WORKAROUND - YEAR 0 ISSUE - see STACKITSDK-202 } }
97+ { {! Workaround should be removed during work on STACKITSDK-260 } }
98+ { {#isDateTime} }
99+ @field_validator('{ {{name} }}', mode='before')
100+ def { {{name} }}_change_year_zero_to_one(cls, value):
101+ """Workaround which prevents year 0 issue"""
102+ if isinstance(value, str):
103+ # Check for year "0000" at the beginning of the string
104+ # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
105+ 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):
106+ # Workaround: Replace "0000" with "0001"
107+ return "0001" + value[4:] # Take "0001" and append the rest of the string
108+ return value
109+ { {/isDateTime} }
110+ { {! END OF WORKAROUND - YEAR 0 ISSUE } }
94111{ {/vars} }
95112
96113 model_config = ConfigDict(
You can’t perform that action at this time.
0 commit comments