Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude unset fields in search response #168

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)

## [v1.0.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ async def post_search(
filter_kwargs = search_request.fields.filter_fields

items = [
orjson.loads(stac_pydantic.Item(**feat).json(**filter_kwargs))
orjson.loads(
stac_pydantic.Item(**feat).json(**filter_kwargs, exclude_unset=True)
)
for feat in items
]

Expand Down
17 changes: 17 additions & 0 deletions stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ async def test_app_fields_extension_no_properties_post(app_client, ctx, txn_clie
assert "properties" not in resp_json["features"][0]


@pytest.mark.asyncio
async def test_app_fields_extension_no_null_fields(app_client, ctx, txn_client):
resp = await app_client.get("/search", params={"collections": ["test-collection"]})
assert resp.status_code == 200
resp_json = resp.json()
# check if no null fields: https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166
for feature in resp_json["features"]:
# assert "bbox" not in feature["geometry"]
for link in feature["links"]:
assert all(a not in link or link[a] is not None for a in ("title", "asset"))
for asset in feature["assets"]:
assert all(
a not in asset or asset[a] is not None
for a in ("start_datetime", "created")
)


@pytest.mark.asyncio
async def test_app_fields_extension_return_all_properties(app_client, ctx, txn_client):
item = ctx.item
Expand Down