diff --git a/services/intake/src/stackit/intake/models/intake_response.py b/services/intake/src/stackit/intake/models/intake_response.py index 2f6287974..b560a81f9 100644 --- a/services/intake/src/stackit/intake/models/intake_response.py +++ b/services/intake/src/stackit/intake/models/intake_response.py @@ -15,6 +15,7 @@ import json import pprint +import re # noqa: F401 from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set @@ -75,6 +76,19 @@ class IntakeResponse(BaseModel): "uri", ] + @field_validator("create_time", mode="before") + def create_time_change_year_zero_to_one(cls, value): + """Workaround which prevents year 0 issue""" + if isinstance(value, str): + # Check for year "0000" at the beginning of the string + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ + 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 + ): + # Workaround: Replace "0000" with "0001" + return "0001" + value[4:] # Take "0001" and append the rest of the string + return value + @field_validator("state") def state_validate_enum(cls, value): """Validates the enum""" diff --git a/services/intake/src/stackit/intake/models/intake_runner_response.py b/services/intake/src/stackit/intake/models/intake_runner_response.py index 55d180ddf..1a6d06583 100644 --- a/services/intake/src/stackit/intake/models/intake_runner_response.py +++ b/services/intake/src/stackit/intake/models/intake_runner_response.py @@ -15,6 +15,7 @@ import json import pprint +import re # noqa: F401 from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set @@ -59,6 +60,19 @@ class IntakeRunnerResponse(BaseModel): "uri", ] + @field_validator("create_time", mode="before") + def create_time_change_year_zero_to_one(cls, value): + """Workaround which prevents year 0 issue""" + if isinstance(value, str): + # Check for year "0000" at the beginning of the string + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ + 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 + ): + # Workaround: Replace "0000" with "0001" + return "0001" + value[4:] # Take "0001" and append the rest of the string + return value + @field_validator("state") def state_validate_enum(cls, value): """Validates the enum""" diff --git a/services/intake/src/stackit/intake/models/intake_user_response.py b/services/intake/src/stackit/intake/models/intake_user_response.py index 4cabce2b2..53587f9f0 100644 --- a/services/intake/src/stackit/intake/models/intake_user_response.py +++ b/services/intake/src/stackit/intake/models/intake_user_response.py @@ -15,6 +15,7 @@ import json import pprint +import re # noqa: F401 from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set @@ -58,6 +59,19 @@ class IntakeUserResponse(BaseModel): "user", ] + @field_validator("create_time", mode="before") + def create_time_change_year_zero_to_one(cls, value): + """Workaround which prevents year 0 issue""" + if isinstance(value, str): + # Check for year "0000" at the beginning of the string + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ + 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 + ): + # Workaround: Replace "0000" with "0001" + return "0001" + value[4:] # Take "0001" and append the rest of the string + return value + @field_validator("state") def state_validate_enum(cls, value): """Validates the enum"""