From 5618f1a6760d0bcb811b621751af94b7de16c4d9 Mon Sep 17 00:00:00 2001 From: Mike Cantelon Date: Wed, 18 Sep 2024 17:56:15 -0700 Subject: [PATCH] Fix format-related Typesense report errors (#342) Don't bother doing a counts of formats, and format versions, of files matching report criteria if no formats, or format versions, were found (given that others a multi-search Typesense query will be sent with no searches and will result in an HTTP 500 error). --- AIPscan/Data/report_data_typesense.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/AIPscan/Data/report_data_typesense.py b/AIPscan/Data/report_data_typesense.py index 6887bb82..bd212065 100644 --- a/AIPscan/Data/report_data_typesense.py +++ b/AIPscan/Data/report_data_typesense.py @@ -44,6 +44,10 @@ def formats_count( value_counts = ts_helpers.facet_value_counts(results, "file_format") + # If no formats were found then don't proceed to get counts + if len(value_counts) == 0: + return report + format_size_sums = {} if include_size_data: # Request total size of files for each file format @@ -216,9 +220,14 @@ def format_versions_count( ) puid_counts = ts_helpers.facet_value_counts(results, "puid") - puids = list(puid_counts.keys()) + + # If no format versions were found then don't proceed to get counts + if len(puid_counts) == 0: + return report # Request total size of files for each PUID + puids = list(puid_counts.keys()) + search_requests = {"searches": []} for puid in puids: format_filters = file_filters.copy()