diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc23237..46a95128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Fixed issue where searches return an empty `links` array [#241](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/241) ## [v2.4.0] diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 053c8395..950a4f6f 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -318,9 +318,7 @@ async def item_collection( if maybe_count is not None: context_obj["matched"] = maybe_count - links = [] - if next_token: - links = await PagingLinks(request=request, next=next_token).get_links() + links = await PagingLinks(request=request, next=next_token).get_links() return ItemCollection( type="FeatureCollection", @@ -619,9 +617,7 @@ async def post_search( if maybe_count is not None: context_obj["matched"] = maybe_count - links = [] - if next_token: - links = await PagingLinks(request=request, next=next_token).get_links() + links = await PagingLinks(request=request, next=next_token).get_links() return ItemCollection( type="FeatureCollection", diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index 20517f42..f84d9759 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -570,6 +570,15 @@ async def test_get_missing_item_collection(app_client): assert resp.status_code == 404 +@pytest.mark.asyncio +async def test_pagination_base_links(app_client, ctx): + """Test that a search query always contains basic links""" + page = await app_client.get(f"/collections/{ctx.item['collection']}/items") + + page_data = page.json() + assert {"self", "root"}.issubset({link["rel"] for link in page_data["links"]}) + + @pytest.mark.asyncio async def test_pagination_item_collection(app_client, ctx, txn_client): """Test item collection pagination links (paging extension)"""