From 0b08f8102aed18a077ec3d7e6e9f6fe99ff2801d Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 11:04:08 +0800 Subject: [PATCH 1/6] Remove deprecated context extension --- stac_fastapi/core/stac_fastapi/core/core.py | 28 ++++++++----------- .../stac_fastapi/elasticsearch/app.py | 2 -- .../opensearch/stac_fastapi/opensearch/app.py | 2 -- stac_fastapi/tests/api/test_api.py | 2 +- stac_fastapi/tests/conftest.py | 5 +--- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 41d72e7e..522d453e 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -312,14 +312,12 @@ async def item_collection( self.item_serializer.db_to_stac(item, base_url=base_url) for item in items ] - context_obj = None - if self.extension_is_enabled("ContextExtension"): - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count + context_obj = { + "returned": len(items), + "limit": limit, + } + if maybe_count is not None: + context_obj["matched"] = maybe_count links = await PagingLinks(request=request, next=next_token).get_links() @@ -633,14 +631,12 @@ async def post_search( for feat in items ] - context_obj = None - if self.extension_is_enabled("ContextExtension"): - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count + context_obj = { + "returned": len(items), + "limit": limit, + } + if maybe_count is not None: + context_obj["matched"] = maybe_count links = await PagingLinks(request=request, next=next_token).get_links() diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py index 49d199d6..c0d4aaea 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py @@ -20,7 +20,6 @@ create_index_templates, ) from stac_fastapi.extensions.core import ( - ContextExtension, FieldsExtension, FilterExtension, SortExtension, @@ -57,7 +56,6 @@ QueryExtension(), SortExtension(), TokenPaginationExtension(), - ContextExtension(), filter_extension, ] diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py index ac697b2b..4cd38c20 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py @@ -14,7 +14,6 @@ from stac_fastapi.core.extensions import QueryExtension from stac_fastapi.core.session import Session from stac_fastapi.extensions.core import ( - ContextExtension, FieldsExtension, FilterExtension, SortExtension, @@ -57,7 +56,6 @@ QueryExtension(), SortExtension(), TokenPaginationExtension(), - ContextExtension(), filter_extension, ] diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index da94338e..9805af21 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -83,7 +83,7 @@ async def test_app_search_response(app_client, ctx): @pytest.mark.asyncio -async def test_app_context_extension(app_client, txn_client, ctx, load_test_data): +async def test_app_context_results(app_client, txn_client, ctx, load_test_data): test_item = load_test_data("test_item.json") test_item["id"] = "test-item-2" test_item["collection"] = "test-collection-2" diff --git a/stac_fastapi/tests/conftest.py b/stac_fastapi/tests/conftest.py index 80314a45..21380494 100644 --- a/stac_fastapi/tests/conftest.py +++ b/stac_fastapi/tests/conftest.py @@ -38,8 +38,7 @@ create_index_templates, ) -from stac_fastapi.extensions.core import ( # FieldsExtension, - ContextExtension, +from stac_fastapi.extensions.core import ( FieldsExtension, FilterExtension, SortExtension, @@ -193,7 +192,6 @@ async def app(): ), settings=settings, ), - ContextExtension(), SortExtension(), FieldsExtension(), QueryExtension(), @@ -236,7 +234,6 @@ async def app_basic_auth(): ), settings=settings, ), - ContextExtension(), SortExtension(), FieldsExtension(), QueryExtension(), From 421f9b879a0bf3a8243e7951872361e82bb21c92 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 11:07:55 +0800 Subject: [PATCH 2/6] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efad4e5..e4d0aaba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Removed deprecated context extension [#255](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/255) + ## [v3.0.0a0] From c36458e62ea6278e03f7ddd0a78f5145ce631132 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 11:33:44 +0800 Subject: [PATCH 3/6] ues num_matched, returned --- stac_fastapi/core/stac_fastapi/core/core.py | 22 ++++++++------------- stac_fastapi/tests/api/test_api.py | 6 +++--- stac_fastapi/tests/resources/test_item.py | 10 +++++----- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 522d453e..499c54fb 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -312,12 +312,8 @@ async def item_collection( self.item_serializer.db_to_stac(item, base_url=base_url) for item in items ] - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count + num_returned = len(items) + num_matched = maybe_count if maybe_count is not None else None links = await PagingLinks(request=request, next=next_token).get_links() @@ -325,7 +321,8 @@ async def item_collection( type="FeatureCollection", features=items, links=links, - context=context_obj, + num_returned=num_returned, + num_matched=num_matched, ) async def get_item( @@ -631,12 +628,8 @@ async def post_search( for feat in items ] - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count + num_returned = len(items) + num_matched = maybe_count if maybe_count is not None else None links = await PagingLinks(request=request, next=next_token).get_links() @@ -644,7 +637,8 @@ async def post_search( type="FeatureCollection", features=items, links=links, - context=context_obj, + num_returned=num_returned, + num_matched=num_matched, ) diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index 9805af21..5be389b9 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -111,9 +111,8 @@ async def test_app_context_results(app_client, txn_client, ctx, load_test_data): resp_json = resp.json() assert len(resp_json["features"]) == 1 - assert "context" in resp_json - assert resp_json["context"]["returned"] == 1 - if matched := resp_json["context"].get("matched"): + assert resp_json["num_returned"] == 1 + if matched := resp_json.get("num_matched"): assert matched == 1 @@ -225,6 +224,7 @@ async def test_app_query_extension_limit_lt0(app_client): ).status_code == 400 +@pytest.mark.skip(reason="removal of context extension") @pytest.mark.asyncio async def test_app_query_extension_limit_gt10000(app_client): resp = await app_client.post("/search", json={"limit": 10001}) diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index 146077bc..ab3340d8 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -215,7 +215,7 @@ async def test_get_item_collection(app_client, ctx, txn_client): assert resp.status_code == 200 item_collection = resp.json() - if matched := item_collection["context"].get("matched"): + if matched := item_collection.get("num_matched"): assert matched == item_count + 1 @@ -283,13 +283,13 @@ async def test_pagination(app_client, load_test_data): ) assert resp.status_code == 200 first_page = resp.json() - assert first_page["context"]["returned"] == 3 + assert first_page["num_returned"] == 3 url_components = urlsplit(first_page["links"][0]["href"]) resp = await app_client.get(f"{url_components.path}?{url_components.query}") assert resp.status_code == 200 second_page = resp.json() - assert second_page["context"]["returned"] == 3 + assert second_page["num_returned"] == 3 @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): ), } resp = await app_client.get("/search", params=params) - assert resp.json()["context"]["returned"] == 0 + assert resp.json()["num_returned"] == 0 params["query"] = json.dumps( {"proj:epsg": {"eq": test_item["properties"]["proj:epsg"]}} ) resp = await app_client.get("/search", params=params) resp_json = resp.json() - assert resp_json["context"]["returned"] == 1 + assert resp_json["num_returned"] == 1 assert ( resp_json["features"][0]["properties"]["proj:epsg"] == test_item["properties"]["proj:epsg"] From 5dcfbbb87e5a13c3caac2bf5c3c47fba5698f881 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 11:42:09 +0800 Subject: [PATCH 4/6] numMatched, numReturned --- stac_fastapi/core/stac_fastapi/core/core.py | 8 ++++---- stac_fastapi/tests/api/test_api.py | 4 ++-- stac_fastapi/tests/resources/test_item.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 499c54fb..fb66f677 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -321,8 +321,8 @@ async def item_collection( type="FeatureCollection", features=items, links=links, - num_returned=num_returned, - num_matched=num_matched, + numReturned=num_returned, + numMatched=num_matched, ) async def get_item( @@ -637,8 +637,8 @@ async def post_search( type="FeatureCollection", features=items, links=links, - num_returned=num_returned, - num_matched=num_matched, + numReturned=num_returned, + numMatched=num_matched, ) diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index 5be389b9..8f519a0f 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -111,8 +111,8 @@ async def test_app_context_results(app_client, txn_client, ctx, load_test_data): resp_json = resp.json() assert len(resp_json["features"]) == 1 - assert resp_json["num_returned"] == 1 - if matched := resp_json.get("num_matched"): + assert resp_json["numReturned"] == 1 + if matched := resp_json.get("numMatched"): assert matched == 1 diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index ab3340d8..45ce4ea1 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -283,13 +283,13 @@ async def test_pagination(app_client, load_test_data): ) assert resp.status_code == 200 first_page = resp.json() - assert first_page["num_returned"] == 3 + assert first_page["numReturned"] == 3 url_components = urlsplit(first_page["links"][0]["href"]) resp = await app_client.get(f"{url_components.path}?{url_components.query}") assert resp.status_code == 200 second_page = resp.json() - assert second_page["num_returned"] == 3 + assert second_page["numReturned"] == 3 @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): ), } resp = await app_client.get("/search", params=params) - assert resp.json()["num_returned"] == 0 + assert resp.json()["numReturned"] == 0 params["query"] = json.dumps( {"proj:epsg": {"eq": test_item["properties"]["proj:epsg"]}} ) resp = await app_client.get("/search", params=params) resp_json = resp.json() - assert resp_json["num_returned"] == 1 + assert resp_json["numReturned"] == 1 assert ( resp_json["features"][0]["properties"]["proj:epsg"] == test_item["properties"]["proj:epsg"] From 3beaaba81d86582e7af6f5eb2a6fbe348b9d4337 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 22:33:04 +0800 Subject: [PATCH 5/6] simplify --- stac_fastapi/core/stac_fastapi/core/core.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index fb66f677..3fe7d32e 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -312,17 +312,14 @@ async def item_collection( self.item_serializer.db_to_stac(item, base_url=base_url) for item in items ] - num_returned = len(items) - num_matched = maybe_count if maybe_count is not None else None - links = await PagingLinks(request=request, next=next_token).get_links() return stac_types.ItemCollection( type="FeatureCollection", features=items, links=links, - numReturned=num_returned, - numMatched=num_matched, + numReturned=len(items), + numMatched=maybe_count, ) async def get_item( @@ -628,17 +625,14 @@ async def post_search( for feat in items ] - num_returned = len(items) - num_matched = maybe_count if maybe_count is not None else None - links = await PagingLinks(request=request, next=next_token).get_links() return stac_types.ItemCollection( type="FeatureCollection", features=items, links=links, - numReturned=num_returned, - numMatched=num_matched, + numReturned=len(items), + numMatched=maybe_count, ) From 024459ad876568535c38279432cdad7114fd3932 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Sun, 12 May 2024 22:35:25 +0800 Subject: [PATCH 6/6] fix syntax --- stac_fastapi/tests/resources/test_item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index 45ce4ea1..ad30c448 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -215,7 +215,7 @@ async def test_get_item_collection(app_client, ctx, txn_client): assert resp.status_code == 200 item_collection = resp.json() - if matched := item_collection.get("num_matched"): + if matched := item_collection.get("numMatched"): assert matched == item_count + 1