From 900017791aba3ee2455512f27ed684f64612e302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 28 Mar 2024 11:27:16 +0100 Subject: [PATCH] fixes loading of removed attributes. Prints debug log instead of raising exception --- src/pydase/data_service/state_manager.py | 23 ++++++++++++++++------- tests/data_service/test_state_manager.py | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/pydase/data_service/state_manager.py b/src/pydase/data_service/state_manager.py index 75ee556..cd59bf5 100644 --- a/src/pydase/data_service/state_manager.py +++ b/src/pydase/data_service/state_manager.py @@ -13,6 +13,7 @@ from pydase.utils.helpers import ( ) from pydase.utils.serialization.deserializer import loads from pydase.utils.serialization.serializer import ( + SerializationPathError, SerializedObject, generate_serialized_data_paths, get_nested_dict_by_path, @@ -299,12 +300,20 @@ class StateManager: ) return has_decorator - cached_serialization_dict = get_nested_dict_by_path( - self.cache_value, full_access_path - ) + try: + cached_serialization_dict = get_nested_dict_by_path( + self.cache_value, full_access_path + ) - if cached_serialization_dict["value"] == "method": + if cached_serialization_dict["value"] == "method": + return False + + # nested objects cannot be loaded + return not serialized_dict_is_nested_object(cached_serialization_dict) + except SerializationPathError: + logger.debug( + "Path %a could not be loaded. It does not correspond to an attribute of" + " the class. Ignoring value from JSON file...", + attr_name, + ) return False - - # nested objects cannot be loaded - return not serialized_dict_is_nested_object(cached_serialization_dict) diff --git a/tests/data_service/test_state_manager.py b/tests/data_service/test_state_manager.py index e4a69bc..d26d57b 100644 --- a/tests/data_service/test_state_manager.py +++ b/tests/data_service/test_state_manager.py @@ -240,8 +240,8 @@ def test_load_state(tmp_path: Path, caplog: LogCaptureFixture) -> None: "Ignoring value from JSON file..." ) in caplog.text assert ( - "Attribute type of 'removed_attr' changed from 'str' to 'None'. " - "Ignoring value from JSON file..." in caplog.text + "Path 'removed_attr' could not be loaded. It does not correspond to an " + "attribute of the class. Ignoring value from JSON file..." in caplog.text ) assert "Value of attribute 'subservice.name' has not changed..." in caplog.text assert "'my_slider.value' changed to '1.0'" in caplog.text