Skip to content

Commit d3797ef

Browse files
deprecate post_request_model in BaseCoreClient and AsyncBaseCoreClient (#773)
1 parent d2eb81d commit d3797ef

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
## Changed
1717

18-
* use `stac_pydantic.version.STAC_VERSION` instead of `stac_pydantic.api.version.STAC_API_VERSION` as application `stac_version`
18+
* Use `stac_pydantic.version.STAC_VERSION` instead of `stac_pydantic.api.version.STAC_API_VERSION` as application `stac_version`
1919
* Return more informations from pydantic validation errors
20+
* Add deprecation notice for `post_request_model` attribute in `BaseCoreClient` and `AsyncBaseCoreClient`
2021

2122
## [3.0.3] - 2024-10-09
2223

stac_fastapi/api/tests/test_app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,11 @@ def get_search(
165165
type="FeatureCollection", features=[stac.Item(**item_dict)]
166166
)
167167

168-
post_request_model = create_post_request_model([FilterExtension()])
169-
170168
test_app = app.StacApi(
171169
settings=ApiSettings(enable_response_models=validate),
172-
client=FilterClient(post_request_model=post_request_model),
170+
client=FilterClient(),
173171
search_get_request_model=create_get_request_model([FilterExtension()]),
174-
search_post_request_model=post_request_model,
172+
search_post_request_model=create_post_request_model([FilterExtension()]),
175173
extensions=[FilterExtension()],
176174
)
177175

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Base clients."""
22

33
import abc
4+
import warnings
45
from typing import Any, Dict, List, Optional, Union
56
from urllib.parse import urljoin
67

@@ -341,7 +342,20 @@ class BaseCoreClient(LandingPageMixin, abc.ABC):
341342
factory=lambda: BASE_CONFORMANCE_CLASSES
342343
)
343344
extensions: List[ApiExtension] = attr.ib(default=attr.Factory(list))
344-
post_request_model = attr.ib(default=BaseSearchPostRequest)
345+
post_request_model = attr.ib(default=None)
346+
347+
@post_request_model.validator
348+
def _deprecate_post_model(self, attribute, value):
349+
"""Check and raise warning if `post_request_model` is set."""
350+
if value is not None:
351+
warnings.warn(
352+
"`post_request_model` attribute is deprecated and will be removed in 3.1",
353+
DeprecationWarning,
354+
)
355+
356+
def __attrs_post_init__(self):
357+
"""Set default value for post_request_model."""
358+
self.post_request_model = self.post_request_model or BaseSearchPostRequest
345359

346360
def conformance_classes(self) -> List[str]:
347361
"""Generate conformance classes by adding extension conformance to base
@@ -573,7 +587,20 @@ class AsyncBaseCoreClient(LandingPageMixin, abc.ABC):
573587
factory=lambda: BASE_CONFORMANCE_CLASSES
574588
)
575589
extensions: List[ApiExtension] = attr.ib(default=attr.Factory(list))
576-
post_request_model = attr.ib(default=BaseSearchPostRequest)
590+
post_request_model = attr.ib(default=None)
591+
592+
@post_request_model.validator
593+
def _deprecate_post_model(self, attribute, value):
594+
"""Check and raise warning if `post_request_model` is set."""
595+
if value is not None:
596+
warnings.warn(
597+
"`post_request_model` attribute is deprecated and will be removed in 3.1",
598+
DeprecationWarning,
599+
)
600+
601+
def __attrs_post_init__(self):
602+
"""Set default value for post_request_model."""
603+
self.post_request_model = self.post_request_model or BaseSearchPostRequest
577604

578605
def conformance_classes(self) -> List[str]:
579606
"""Generate conformance classes by adding extension conformance to base

0 commit comments

Comments
 (0)