From d16e7f8cc2f94768348fa739141fa38717c92e7c Mon Sep 17 00:00:00 2001 From: Wolkenfarmer Date: Thu, 17 Oct 2024 13:19:15 +0200 Subject: [PATCH] #330 backend: fix crash when activating continuous variable exceptions with nested lists --- .../serializers/continuous_variable_serializer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/dps_training_k/template/serializers/continuous_variable_serializer.py b/backend/dps_training_k/template/serializers/continuous_variable_serializer.py index b8c39fa5..5797bee1 100644 --- a/backend/dps_training_k/template/serializers/continuous_variable_serializer.py +++ b/backend/dps_training_k/template/serializers/continuous_variable_serializer.py @@ -104,6 +104,12 @@ def _get_values(self, variable_name, future_state): future_state.vital_signs ) + def _flatten(self, lst): + """Helper function to recursively flatten a list""" + if isinstance(lst, list): + return tuple(item for sublist in lst for item in self._flatten(sublist)) + return (lst,) + def _get_applicable_function(self, variable): completed_action_uuids = { str(action.uuid) @@ -116,8 +122,12 @@ def _get_applicable_function(self, variable): for exception in variable.exceptions: function = exception["function"] - actions = tuple(exception["actions"]) - materials = tuple(exception["materials"]) + actions = ( + self._flatten(exception["actions"]) if exception["actions"] else () + ) + materials = ( + self._flatten(exception["materials"]) if exception["materials"] else () + ) if _check_subset(actions, completed_action_uuids) and _check_subset( materials, completed_material_uuids