Skip to content

bug: jsonb_strip_nulls() in hydration functions strips datetime: null from item properties, producing invalid STAC items #425

@seedlit

Description

@seedlit

pgstac's database level hydration drops "datetime": null from STAC item properties when reconstructing items for API responses. This produces invalid STAC items when start_datetime/end_datetime are used, because the STAC spec requires "datetime": null to be explicitly present in that case.

Reproduction

1. Ingest an item with datetime: null

Ingest any STAC item that uses a date range (i.e., datetime is null with start_datetime and end_datetime set).

2. Query the item back via the search function

SELECT content_hydrate(items) FROM items WHERE id = '<your-item-id>';

Or via stac-fastapi-pgstac:

curl -s 'http://localhost:8081/collections/<collection>/items?limit=1' | python3 -c "
import json, sys
data = json.load(sys.stdin)
print(json.dumps(data['features'][0]['properties'], indent=2))
"

3. Observe that datetime is missing

Expected:

{
  "datetime": null,
  "start_datetime": "2024-01-01T00:00:00Z",
  "end_datetime": "2024-01-02T00:00:00Z"
}

Actual:

{
  "start_datetime": "2024-01-01T00:00:00Z",
  "end_datetime": "2024-01-02T00:00:00Z"
}

"datetime" is entirely absent from the response, not just null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions