fix(dashboard_chart): use dict.get() to avoid a KeyError
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
d1210f7edc
commit
61dfbe2f9f
1 changed files with 3 additions and 4 deletions
|
|
@ -260,7 +260,7 @@ def get_heatmap_chart_config(chart, filters, heatmap_year):
|
|||
}
|
||||
|
||||
|
||||
def get_group_by_chart_config(chart, filters):
|
||||
def get_group_by_chart_config(chart, filters) -> dict | None:
|
||||
aggregate_function = get_aggregate_function(chart.group_by_type)
|
||||
value_field = chart.aggregate_function_based_on or "1"
|
||||
group_by_field = chart.group_by_based_on
|
||||
|
|
@ -281,11 +281,10 @@ def get_group_by_chart_config(chart, filters):
|
|||
|
||||
if data:
|
||||
return {
|
||||
"labels": [item["name"] if item["name"] else "Not Specified" for item in data],
|
||||
"labels": [item.get("name", "Not Specified") for item in data],
|
||||
"datasets": [{"name": chart.name, "values": [item["count"] for item in data]}],
|
||||
}
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def get_aggregate_function(chart_type):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue