Skip to content

Commit

Permalink
Handle missing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
olaughter committed Aug 29, 2024
1 parent b622092 commit 42309a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index/vespa_.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ class MetadataItem(BaseModel):
corpus_type_name: Optional[str] = None
collection_title: Optional[str] = None
collection_summary: Optional[str] = None
metadata: list[MetadataItem]
metadata: Optional[list[MetadataItem]] = None


def reshape_metadata(
metadata: dict[str, list[str]]
) -> list[VespaFamilyDocument.MetadataItem]:
metadata: Optional[dict[str, list[str]]]
) -> Optional[list[VespaFamilyDocument.MetadataItem]]:
if metadata is None:
return None

metadata_items = []
for key, values in metadata.items():
metadata_items.extend(
Expand Down
1 change: 1 addition & 0 deletions tests/src/test_vespa.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
VespaFamilyDocument.MetadataItem(name="sector", value="Water"),
],
),
(None, None),
],
)
def test_reshape_metadata(metadata, expected):
Expand Down

0 comments on commit 42309a7

Please sign in to comment.