Skip to content

Fields extension: specifying both exclude and include for nested fields does not result in expected behavior #361

@mcucchi9

Description

@mcucchi9

Tag: 6.2.1

The STAC API specification for the Fields extension states that (point 5 here):

For nested fields (e.g., properties.datetime), the most specific path should be honored first, and include should be preferred over exclude. For example: i. If a field is in exclude, and a nested field of that field is in include, the nested field should be included, but no other nested fields in the field should be included. For example, if properties is excluded and properties.datetime is included, then datetime should be the only nested field in properties.

On the contrary, performing a POST /search request to an instance of the stac-fastapi-pgstac API with the following payload

{
    "fields": {
        "exclude": ["properties"],
        "include": ["properties.datetime"]
    }
}

results in a FeatureCollection in which each Feature misses the properties field entirely.

Digging into the code, I can see this behavior is probably due to the logic in the filter_fields function of stac_fastapi/pgstac/utils.py, in which the exclude and include operations are sequential with no special attention to such cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions