Skip to content

Commit

Permalink
Exclude nones in parent_catalogs only if exclude_none=True
Browse files Browse the repository at this point in the history
Co-authored-by: Brian Cherinka <[email protected]>
  • Loading branch information
albireox and havok2063 authored Aug 7, 2024
1 parent abc21e4 commit 91d87ed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/valis/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ class CatalogResponse(CatalogModel, SDSSidFlatBase):
parent_catalogs: dict[str, Any] = Field(..., description='The parent catalog associations for a given catalogid')

@field_serializer('parent_catalogs')
def serialize_parent_catalogs(v: dict[str, Any]) -> dict[str, Any]:
def serialize_parent_catalogs(v: dict[str, Any], info: FieldSerializationInfo) -> dict[str, Any]:
""" Serialize the parent catalogs, excluding None values."""

return {k: v for k, v in v.items() if v is not None}
if info.exclude_none:
return {k: v for k, v in v.items() if v is not None}
else:
return v


class CartonModel(PeeweeBase):
Expand Down

0 comments on commit 91d87ed

Please sign in to comment.