mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 05:30:39 +02:00
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:
commit
2399b3ca9f
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user