Merge pull request #71 from tiqi-group/fix/update_task_status

Fix: update task status
This commit is contained in:
Mose Müller 2023-11-16 10:26:22 +01:00 committed by GitHub
commit 0cd3a7e8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -311,8 +311,11 @@ class Server:
get_nested_dict_by_path(self._state_manager.cache, full_access_path) get_nested_dict_by_path(self._state_manager.cache, full_access_path)
) )
serialized_value = dump(value) serialized_value = dump(value)
if cached_value_dict["type"] != "method":
cached_value_dict["type"] = serialized_value["type"]
cached_value_dict["value"] = serialized_value["value"] cached_value_dict["value"] = serialized_value["value"]
cached_value_dict["type"] = serialized_value["type"]
async def notify() -> None: async def notify() -> None:
try: try:

View File

@ -259,8 +259,9 @@ def set_nested_value_by_path(
# setting the new value # setting the new value
serialized_value = dump(value) serialized_value = dump(value)
if "readonly" in current_dict: if "readonly" in current_dict:
if current_dict["type"] != "method":
current_dict["type"] = serialized_value["type"]
current_dict["value"] = serialized_value["value"] current_dict["value"] = serialized_value["value"]
current_dict["type"] = serialized_value["type"]
else: else:
current_dict.update(serialized_value) current_dict.update(serialized_value)

View File

@ -23,3 +23,20 @@ def test_nested_attributes_cache_callback() -> None:
test_service.class_attr.name = "Ciao" test_service.class_attr.name = "Ciao"
assert get_nested_dict_by_path(cache.cache, "class_attr.name")["value"] == "Ciao" assert get_nested_dict_by_path(cache.cache, "class_attr.name")["value"] == "Ciao"
def test_task_status_update() -> None:
class ServiceClass(pydase.DataService):
name = "World"
async def my_method(self) -> None:
pass
test_service = ServiceClass()
cache = DataServiceCache(test_service)
assert get_nested_dict_by_path(cache.cache, "my_method")["type"] == "method"
assert get_nested_dict_by_path(cache.cache, "my_method")["value"] is None
test_service.start_my_method() # type: ignore
assert get_nested_dict_by_path(cache.cache, "my_method")["type"] == "method"
assert get_nested_dict_by_path(cache.cache, "my_method")["value"] == {}