Merge pull request #214 from tiqi-group/192-starting-a-task-on-a-dataservice-exposed-as-a-property-causes-the-button-to-spin-indefinitely

fix: correctly handle observable properties
This commit is contained in:
Mose Müller 2025-03-28 09:44:11 +01:00 committed by GitHub
commit 2399b3ca9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -55,6 +55,10 @@ class Observable(ObservableObject):
value = super().__getattribute__(name) value = super().__getattribute__(name)
if is_property_attribute(self, name): if is_property_attribute(self, name):
# fixes https://github.com/tiqi-group/pydase/issues/187 and
# https://github.com/tiqi-group/pydase/issues/192
if isinstance(value, ObservableObject):
value.add_observer(self, name)
self._notify_changed(name, value) self._notify_changed(name, value)
return value return value

View File

@ -222,3 +222,22 @@ def test_nested_dict_property_changes(
# Changing the _voltage attribute should re-evaluate the voltage property, but avoid # Changing the _voltage attribute should re-evaluate the voltage property, but avoid
# recursion # recursion
service.my_dict["key"].voltage = 1.2 service.my_dict["key"].voltage = 1.2
def test_read_only_dict_property(caplog: pytest.LogCaptureFixture) -> None:
class MyObservable(pydase.DataService):
def __init__(self) -> None:
super().__init__()
self._dict_attr = {"dotted.key": 1.0}
@property
def dict_attr(self) -> dict[str, Any]:
return self._dict_attr
service_instance = MyObservable()
state_manager = StateManager(service=service_instance)
DataServiceObserver(state_manager)
service_instance._dict_attr["dotted.key"] = 2.0
assert "'dict_attr[\"dotted.key\"]' changed to '2.0'" in caplog.text