Skip to content

Commit

Permalink
fix: exclude optional collection values
Browse files Browse the repository at this point in the history
If we're not using response models, we can't automagically exclude none values.
  • Loading branch information
gadomski committed Jan 13, 2023
1 parent 7d0fb57 commit 3bff044
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,28 @@ def db_to_stac(cls, db_model: database.Collection, base_url: str) -> TypedDict:
if db_links:
collection_links += resolve_links(db_links, base_url)

stac_extensions = db_model.stac_extensions or []

return stac_types.Collection(
collection = stac_types.Collection(
type="Collection",
id=db_model.id,
stac_extensions=stac_extensions,
stac_version=db_model.stac_version,
title=db_model.title,
description=db_model.description,
keywords=db_model.keywords,
license=db_model.license,
providers=db_model.providers,
summaries=db_model.summaries,
extent=db_model.extent,
links=collection_links,
)
# We need to manually include optional values to ensure they are
# excluded if we're not using response models.
if db_model.stac_extensions:
collection["stac_extensions"] = db_model.stac_extensions
if db_model.title:
collection["title"] = db_model.title
if db_model.keywords:
collection["keywords"] = db_model.keywords
if db_model.providers:
collection["providers"] = db_model.providers
if db_model.summaries:
collection["summaries"] = db_model.summaries
return collection

@classmethod
def stac_to_db(
Expand Down

0 comments on commit 3bff044

Please sign in to comment.