Skip to content

Commit 9638bd1

Browse files
committed
fix(search): clear datetime between searches
1 parent fa2df27 commit 9638bd1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Diff for: stac_pydantic/api/search.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
Point,
1111
Polygon,
1212
)
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+
)
1421

1522
from stac_pydantic.api.extensions.fields import FieldsExtension
1623
from stac_pydantic.api.extensions.query import Operator
@@ -45,8 +52,17 @@ class Search(BaseModel):
4552
limit: Optional[int] = 10
4653

4754
# 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
5066

5167
# Properties to return the private values
5268
@property
@@ -133,8 +149,8 @@ def validate_datetime(cls, value: Optional[str]) -> Optional[str]:
133149
)
134150

135151
# 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]
138154
# Return the original string value
139155
return value
140156

0 commit comments

Comments
 (0)