|
10 | 10 | Point,
|
11 | 11 | Polygon,
|
12 | 12 | )
|
13 |
| -from pydantic import BaseModel, Field, TypeAdapter, field_validator, model_validator |
| 13 | +from pydantic import ( |
| 14 | + BaseModel, |
| 15 | + Field, |
| 16 | + PrivateAttr, |
| 17 | + TypeAdapter, |
| 18 | + field_validator, |
| 19 | + model_validator, |
| 20 | +) |
14 | 21 |
|
15 | 22 | from stac_pydantic.api.extensions.fields import FieldsExtension
|
16 | 23 | from stac_pydantic.api.extensions.query import Operator
|
@@ -45,8 +52,17 @@ class Search(BaseModel):
|
45 | 52 | limit: Optional[int] = 10
|
46 | 53 |
|
47 | 54 | # Private properties to store the parsed datetime values. Not part of the model schema.
|
48 |
| - _start_date: Optional[dt] = None |
49 |
| - _end_date: Optional[dt] = None |
| 55 | + _start_date: Optional[dt] = PrivateAttr(default=None) |
| 56 | + _end_date: Optional[dt] = PrivateAttr(default=None) |
| 57 | + |
| 58 | + def __init__(self, **data: Any) -> None: |
| 59 | + super().__init__(**data) |
| 60 | + # Copy class variables to the instance variables |
| 61 | + self._start_date = getattr(self.__class__, "_start_date_cls", None) |
| 62 | + self._end_date = getattr(self.__class__, "_end_date_cls", None) |
| 63 | + # Reset class variables |
| 64 | + self.__class__._start_date_cls = None |
| 65 | + self.__class__._end_date_cls = None |
50 | 66 |
|
51 | 67 | # Properties to return the private values
|
52 | 68 | @property
|
@@ -133,8 +149,8 @@ def validate_datetime(cls, value: Optional[str]) -> Optional[str]:
|
133 | 149 | )
|
134 | 150 |
|
135 | 151 | # Store the parsed dates
|
136 |
| - cls._start_date = dates[0] |
137 |
| - cls._end_date = dates[1] |
| 152 | + cls._start_date_cls = dates[0] |
| 153 | + cls._end_date_cls = dates[1] |
138 | 154 | # Return the original string value
|
139 | 155 | return value
|
140 | 156 |
|
|
0 commit comments