Skip to content

Commit 3bff044

Browse files
committed
fix: exclude optional collection values
If we're not using response models, we can't automagically exclude none values.
1 parent 7d0fb57 commit 3bff044

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/serializers.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,28 @@ def db_to_stac(cls, db_model: database.Collection, base_url: str) -> TypedDict:
146146
if db_links:
147147
collection_links += resolve_links(db_links, base_url)
148148

149-
stac_extensions = db_model.stac_extensions or []
150-
151-
return stac_types.Collection(
149+
collection = stac_types.Collection(
152150
type="Collection",
153151
id=db_model.id,
154-
stac_extensions=stac_extensions,
155152
stac_version=db_model.stac_version,
156-
title=db_model.title,
157153
description=db_model.description,
158-
keywords=db_model.keywords,
159154
license=db_model.license,
160-
providers=db_model.providers,
161-
summaries=db_model.summaries,
162155
extent=db_model.extent,
163156
links=collection_links,
164157
)
158+
# We need to manually include optional values to ensure they are
159+
# excluded if we're not using response models.
160+
if db_model.stac_extensions:
161+
collection["stac_extensions"] = db_model.stac_extensions
162+
if db_model.title:
163+
collection["title"] = db_model.title
164+
if db_model.keywords:
165+
collection["keywords"] = db_model.keywords
166+
if db_model.providers:
167+
collection["providers"] = db_model.providers
168+
if db_model.summaries:
169+
collection["summaries"] = db_model.summaries
170+
return collection
165171

166172
@classmethod
167173
def stac_to_db(

0 commit comments

Comments
 (0)