Skip to content

Commit 032173b

Browse files
authored
Remove deprecated context extension (#255)
**Related Issue(s):** - radiantearth/stac-api-spec#396 - stac-utils/pgstac#254 **Description:** **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
1 parent a29c2af commit 032173b

File tree

7 files changed

+18
-37
lines changed

7 files changed

+18
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Removed deprecated context extension [#255](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/255)
13+
1014

1115
## [v3.0.0a0]
1216

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,14 @@ async def item_collection(
312312
self.item_serializer.db_to_stac(item, base_url=base_url) for item in items
313313
]
314314

315-
context_obj = None
316-
if self.extension_is_enabled("ContextExtension"):
317-
context_obj = {
318-
"returned": len(items),
319-
"limit": limit,
320-
}
321-
if maybe_count is not None:
322-
context_obj["matched"] = maybe_count
323-
324315
links = await PagingLinks(request=request, next=next_token).get_links()
325316

326317
return stac_types.ItemCollection(
327318
type="FeatureCollection",
328319
features=items,
329320
links=links,
330-
context=context_obj,
321+
numReturned=len(items),
322+
numMatched=maybe_count,
331323
)
332324

333325
async def get_item(
@@ -633,22 +625,14 @@ async def post_search(
633625
for feat in items
634626
]
635627

636-
context_obj = None
637-
if self.extension_is_enabled("ContextExtension"):
638-
context_obj = {
639-
"returned": len(items),
640-
"limit": limit,
641-
}
642-
if maybe_count is not None:
643-
context_obj["matched"] = maybe_count
644-
645628
links = await PagingLinks(request=request, next=next_token).get_links()
646629

647630
return stac_types.ItemCollection(
648631
type="FeatureCollection",
649632
features=items,
650633
links=links,
651-
context=context_obj,
634+
numReturned=len(items),
635+
numMatched=maybe_count,
652636
)
653637

654638

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
create_index_templates,
2121
)
2222
from stac_fastapi.extensions.core import (
23-
ContextExtension,
2423
FieldsExtension,
2524
FilterExtension,
2625
SortExtension,
@@ -57,7 +56,6 @@
5756
QueryExtension(),
5857
SortExtension(),
5958
TokenPaginationExtension(),
60-
ContextExtension(),
6159
filter_extension,
6260
]
6361

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from stac_fastapi.core.extensions import QueryExtension
1515
from stac_fastapi.core.session import Session
1616
from stac_fastapi.extensions.core import (
17-
ContextExtension,
1817
FieldsExtension,
1918
FilterExtension,
2019
SortExtension,
@@ -57,7 +56,6 @@
5756
QueryExtension(),
5857
SortExtension(),
5958
TokenPaginationExtension(),
60-
ContextExtension(),
6159
filter_extension,
6260
]
6361

stac_fastapi/tests/api/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def test_app_search_response(app_client, ctx):
8383

8484

8585
@pytest.mark.asyncio
86-
async def test_app_context_extension(app_client, txn_client, ctx, load_test_data):
86+
async def test_app_context_results(app_client, txn_client, ctx, load_test_data):
8787
test_item = load_test_data("test_item.json")
8888
test_item["id"] = "test-item-2"
8989
test_item["collection"] = "test-collection-2"
@@ -111,9 +111,8 @@ async def test_app_context_extension(app_client, txn_client, ctx, load_test_data
111111

112112
resp_json = resp.json()
113113
assert len(resp_json["features"]) == 1
114-
assert "context" in resp_json
115-
assert resp_json["context"]["returned"] == 1
116-
if matched := resp_json["context"].get("matched"):
114+
assert resp_json["numReturned"] == 1
115+
if matched := resp_json.get("numMatched"):
117116
assert matched == 1
118117

119118

@@ -225,6 +224,7 @@ async def test_app_query_extension_limit_lt0(app_client):
225224
).status_code == 400
226225

227226

227+
@pytest.mark.skip(reason="removal of context extension")
228228
@pytest.mark.asyncio
229229
async def test_app_query_extension_limit_gt10000(app_client):
230230
resp = await app_client.post("/search", json={"limit": 10001})

stac_fastapi/tests/conftest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
create_index_templates,
3939
)
4040

41-
from stac_fastapi.extensions.core import ( # FieldsExtension,
42-
ContextExtension,
41+
from stac_fastapi.extensions.core import (
4342
FieldsExtension,
4443
FilterExtension,
4544
SortExtension,
@@ -193,7 +192,6 @@ async def app():
193192
),
194193
settings=settings,
195194
),
196-
ContextExtension(),
197195
SortExtension(),
198196
FieldsExtension(),
199197
QueryExtension(),
@@ -236,7 +234,6 @@ async def app_basic_auth():
236234
),
237235
settings=settings,
238236
),
239-
ContextExtension(),
240237
SortExtension(),
241238
FieldsExtension(),
242239
QueryExtension(),

stac_fastapi/tests/resources/test_item.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async def test_get_item_collection(app_client, ctx, txn_client):
215215
assert resp.status_code == 200
216216

217217
item_collection = resp.json()
218-
if matched := item_collection["context"].get("matched"):
218+
if matched := item_collection.get("numMatched"):
219219
assert matched == item_count + 1
220220

221221

@@ -283,13 +283,13 @@ async def test_pagination(app_client, load_test_data):
283283
)
284284
assert resp.status_code == 200
285285
first_page = resp.json()
286-
assert first_page["context"]["returned"] == 3
286+
assert first_page["numReturned"] == 3
287287

288288
url_components = urlsplit(first_page["links"][0]["href"])
289289
resp = await app_client.get(f"{url_components.path}?{url_components.query}")
290290
assert resp.status_code == 200
291291
second_page = resp.json()
292-
assert second_page["context"]["returned"] == 3
292+
assert second_page["numReturned"] == 3
293293

294294

295295
@pytest.mark.skip(reason="created and updated fields not be added with stac fastapi 3?")
@@ -547,14 +547,14 @@ async def test_item_search_get_query_extension(app_client, ctx):
547547
),
548548
}
549549
resp = await app_client.get("/search", params=params)
550-
assert resp.json()["context"]["returned"] == 0
550+
assert resp.json()["numReturned"] == 0
551551

552552
params["query"] = json.dumps(
553553
{"proj:epsg": {"eq": test_item["properties"]["proj:epsg"]}}
554554
)
555555
resp = await app_client.get("/search", params=params)
556556
resp_json = resp.json()
557-
assert resp_json["context"]["returned"] == 1
557+
assert resp_json["numReturned"] == 1
558558
assert (
559559
resp_json["features"][0]["properties"]["proj:epsg"]
560560
== test_item["properties"]["proj:epsg"]

0 commit comments

Comments
 (0)