Skip to content

Commit 064f47a

Browse files
committed
exclude hydrate markers
1 parent 717d6c1 commit 064f47a

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"typing_extensions>=4.9.0",
2121
"jsonpatch>=1.33.0",
2222
"json-merge-patch>=0.3.0",
23+
"hydraters>=0.1.3",
2324
]
2425

2526
extra_reqs = {

stac_fastapi/pgstac/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ class Settings(ApiSettings):
184184
185185
ref: https://stac-utils.github.io/pgstac/pgstac/#runtime-configurations
186186
"""
187+
exclude_hydrate_markers: bool = True
188+
"""
189+
In some case, PgSTAC can return `DO_NOT_MERGE_MARKER` markers (`𒍟※`).
190+
If `EXCLUDE_HYDRATE_MARKERS=TRUE` and `USE_API_HYDRATE=TRUE`, stac-fastapi-pgstac
191+
will exclude those values from the responses.
192+
"""
193+
187194
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
188195
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
189196

stac_fastapi/pgstac/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ async def _get_base_item(collection_id: str) -> Dict[str, Any]:
331331
# Exclude None values
332332
base_item = {k: v for k, v in base_item.items() if v is not None}
333333

334-
feature = hydrate(base_item, feature)
334+
feature = hydrate(
335+
base_item,
336+
feature,
337+
strip_unmatched_markers=settings.exclude_hydrate_markers,
338+
)
335339

336340
# Grab ids needed for links that may be removed by the fields extension.
337341
collection_id = feature.get("collection")

tests/resources/test_item.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,9 @@ async def test_item_asset_change(app_client, load_test_data):
17861786
resp.json()["features"][0]["assets"]["red"]["raster:bands"][0]
17871787
)
17881788

1789-
# NOTE: `description` is not in the original item but in the collection's item-assets
1790-
# We get "𒍟※" because PgSTAC set it when ingesting (`description`is item-assets)
1791-
# because we removed item-assets, pgstac cannot hydrate this field, and thus return "𒍟※"
1792-
assert resp.json()["features"][0]["assets"]["qa_pixel"]["description"] == "𒍟※"
1789+
# Only run this test for PgSTAC hydratation because `exclude_hydrate_markers=True` by default
1790+
if not app_client._transport.app.state.settings.use_api_hydrate:
1791+
# NOTE: `description` is not in the original item but in the collection's item-assets
1792+
# We get "𒍟※" because PgSTAC set it when ingesting (`description`is item-assets)
1793+
# because we removed item-assets, pgstac cannot hydrate this field, and thus return "𒍟※"
1794+
assert resp.json()["features"][0]["assets"]["qa_pixel"]["description"] == "𒍟※"

0 commit comments

Comments
 (0)