From 148e4499959078a36ec723f5409e1781fba51bc1 Mon Sep 17 00:00:00 2001 From: "Etienne Scholly, Ph.D" <145967193+drscholly@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:36:52 +0100 Subject: [PATCH] Add security check in handle_timeserie (#29) This is done to avoid crashing when the object has a timeserie attribute without value. --- toolbox/api/datagalaxy_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toolbox/api/datagalaxy_api.py b/toolbox/api/datagalaxy_api.py index 05c1a87..dab86c1 100644 --- a/toolbox/api/datagalaxy_api.py +++ b/toolbox/api/datagalaxy_api.py @@ -98,9 +98,11 @@ def handle_timeserie(property: dict) -> dict: # Temporary solution: only copy the latest value of the TimeSerie for key, value in property.items(): if isinstance(value, dict): - if 'lastEntry' in value: + if 'lastEntry' in value and value['lastEntry'] is not None: # Expected format : "Date::Value" - property[key] = f"{value['lastEntry']['date']}::{value['lastEntry']['value']}" + last_entry = value['lastEntry'] + if 'date' in last_entry and 'value' in last_entry: + property[key] = f"{last_entry['date']}::{last_entry['value']}" def to_bulk_tree(properties: list) -> list: