diff --git a/services/modelserving/src/stackit/modelserving/models/token.py b/services/modelserving/src/stackit/modelserving/models/token.py index 1d74ce13d..af54ee7f5 100644 --- a/services/modelserving/src/stackit/modelserving/models/token.py +++ b/services/modelserving/src/stackit/modelserving/models/token.py @@ -61,6 +61,19 @@ def state_validate_enum(cls, value): raise ValueError("must be one of enum values ('creating', 'active', 'deleting', 'inactive')") return value + @field_validator("valid_until", mode="before") + def valid_until_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 + model_config = ConfigDict( populate_by_name=True, validate_assignment=True, diff --git a/services/modelserving/src/stackit/modelserving/models/token_created.py b/services/modelserving/src/stackit/modelserving/models/token_created.py index b3b0d695a..e043eb1fe 100644 --- a/services/modelserving/src/stackit/modelserving/models/token_created.py +++ b/services/modelserving/src/stackit/modelserving/models/token_created.py @@ -69,6 +69,19 @@ def state_validate_enum(cls, value): raise ValueError("must be one of enum values ('creating', 'active', 'deleting')") return value + @field_validator("valid_until", mode="before") + def valid_until_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 + model_config = ConfigDict( populate_by_name=True, validate_assignment=True,