From b6db3ed86b321bb13b99ccea1e1a8ab144fe048a Mon Sep 17 00:00:00 2001 From: Philip Montgomery Date: Tue, 23 Jul 2024 11:25:04 -0400 Subject: [PATCH] bug fix: prevent thrown exception when indexed property is missing This often happens when updating datasets because the properties to index will include a property which hasn't been uploaded yet. --- breadbox/breadbox/crud/dataset.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/breadbox/breadbox/crud/dataset.py b/breadbox/breadbox/crud/dataset.py index f63578e5..4e4e2b00 100644 --- a/breadbox/breadbox/crud/dataset.py +++ b/breadbox/breadbox/crud/dataset.py @@ -376,16 +376,22 @@ def create_index_records_for_row( db.query(Dataset).filter(Dataset.id == referenced_dataset_id).one() ) - if ( - row.property_metadata[property].annotation_type - == AnnotationType.list_strings - ): - values = cast_tabular_cell_value_type( - row.property_metadata[property].value, - row.property_metadata[property].annotation_type, - ) + if property not in row.property_metadata: + # if the property doesn't exist, just skip it instead of throwing an exception + # This often happens when updating datasets because the properties to index + # will include a property which hasn't been uploaded yet. + continue else: - values = [row.property_metadata[property].value] + if ( + row.property_metadata[property].annotation_type + == AnnotationType.list_strings + ): + values = cast_tabular_cell_value_type( + row.property_metadata[property].value, + row.property_metadata[property].annotation_type, + ) + else: + values = [row.property_metadata[property].value] assert isinstance(values, list) parent_dimension_id = row.property_metadata[property].dimension_id