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

null fields in item search #166

Closed
StijnCaerts opened this issue Nov 20, 2023 · 2 comments
Closed

null fields in item search #166

StijnCaerts opened this issue Nov 20, 2023 · 2 comments

Comments

@StijnCaerts
Copy link
Collaborator

Describe the bug
When the fields extension is enabled, the search response will include null for every field that is not defined in an item.

To Reproduce
Steps to reproduce the behavior:

  1. Ingest STAC Item with minimal metadata, eg. https://github.com/radiantearth/stac-spec/blob/master/examples/simple-item.json
  2. Send GET or POST /search request
  3. The response contains null for the following fields of the features:
    • geometry.bbox
    • assets.*.description
    • assets.*.start_datetime
    • assets.*.created
    • ...
    • links[*].title
    • links[*].label

Expected behavior
According to the STAC API Fields extension, a field should not be specified in the search response if it does not apply to an Item.
https://github.com/stac-api-extensions/fields/blob/6662435f98b8fff6e5d8ffa0f212e3241a10bc6f/README.md?plain=1#L58-L61

Additional context
This bug can be solved in the following ways:
Fix it in stac-fastapi-elasticsearch by adding the exclude_unset=True parameter to the .json() call.
https://github.com/stac-utils/stac-fastapi-elasticsearch/blob/5f26c325940761da7ecd86677da7acceea69bb78/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py#L512

Or fix it in stac-fastapi by adding exclude_unset to the PostFieldsExtension:filter_fields dictionary.
https://github.com/stac-utils/stac-fastapi/blob/09dac221d86fe70035aa6cddbc9a3f0de304aff5/stac_fastapi/extensions/stac_fastapi/extensions/core/fields/request.py#L57-L60

@StijnCaerts StijnCaerts changed the title null fields in in item search null fields in item search Nov 20, 2023
@jonhealy1
Copy link
Collaborator

Do you want to make a pr for this here? Theoretically it can be set both places?

@StijnCaerts
Copy link
Collaborator Author

It can only be set in one place, as you can only supply one value for a keyword argument.
Judging from a quick GitHub search, it seems like stac-fastapi-elasticsearch is the only project using the filter_fields property to get the desired output from pydantic, so I'll create a PR here.

StijnCaerts added a commit to StijnCaerts/stac-fastapi-elasticsearch that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants