|
15 | 15 |
|
16 | 16 | import json |
17 | 17 | import pprint |
| 18 | +import re # noqa: F401 |
18 | 19 | from datetime import datetime |
19 | 20 | from typing import Any, ClassVar, Dict, List, Optional, Set |
20 | 21 |
|
@@ -80,6 +81,32 @@ class Key(BaseModel): |
80 | 81 | "state", |
81 | 82 | ] |
82 | 83 |
|
| 84 | + @field_validator("created_at", mode="before") |
| 85 | + def created_at_change_year_zero_to_one(cls, value): |
| 86 | + """Workaround which prevents year 0 issue""" |
| 87 | + if isinstance(value, str): |
| 88 | + # Check for year "0000" at the beginning of the string |
| 89 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 90 | + if value.startswith("0000-01-01T") and re.match( |
| 91 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 92 | + ): |
| 93 | + # Workaround: Replace "0000" with "0001" |
| 94 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 95 | + return value |
| 96 | + |
| 97 | + @field_validator("deletion_date", mode="before") |
| 98 | + def deletion_date_change_year_zero_to_one(cls, value): |
| 99 | + """Workaround which prevents year 0 issue""" |
| 100 | + if isinstance(value, str): |
| 101 | + # Check for year "0000" at the beginning of the string |
| 102 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 103 | + if value.startswith("0000-01-01T") and re.match( |
| 104 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 105 | + ): |
| 106 | + # Workaround: Replace "0000" with "0001" |
| 107 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 108 | + return value |
| 109 | + |
83 | 110 | @field_validator("state") |
84 | 111 | def state_validate_enum(cls, value): |
85 | 112 | """Validates the enum""" |
|
0 commit comments