From 559ba929c7a9a836571be69a3506bbb4edcb3edb Mon Sep 17 00:00:00 2001 From: Marc-AntoineA Date: Mon, 24 Jun 2024 16:27:48 +0200 Subject: [PATCH] =?UTF-8?q?fix:=E2=80=AFfix=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/charts.py | 14 +++++++++----- app/query.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/charts.py b/app/charts.py index 6f66ec19..61f16a66 100644 --- a/app/charts.py +++ b/app/charts.py @@ -1,16 +1,20 @@ -from ._types import SuccessSearchResponse +from ._types import SuccessSearchResponse, ChartsInfos def build_charts( search_result: SuccessSearchResponse, charts_names: list[str] | None, -) -> str: - charts = {} - if charts_names is None: +) -> ChartsInfos: + charts: ChartsInfos = {} + aggregations = search_result.aggregations + + if charts_names is None or aggregations is None: return charts for chart_name in charts_names: - buckets = search_result.aggregations[chart_name]["buckets"] + agg_data = aggregations.get(chart_name, {}) + + buckets = agg_data.get('buckets', []) if agg_data else [] # Filter unknown values values = [ diff --git a/app/query.py b/app/query.py index 3c730f20..a7a34444 100644 --- a/app/query.py +++ b/app/query.py @@ -281,7 +281,7 @@ def parse_sort_by_script( def create_aggregation_clauses( - config: IndexConfig, fields: list[str] | None + config: IndexConfig, fields: set[str] | list[str] | None ) -> dict[str, Agg]: """Create term bucket aggregation clauses for all fields corresponding to facets,