diff options
| author | Raf Geens <raf@odoo.com> | 2021-05-05 11:10:18 +0000 |
|---|---|---|
| committer | lejeune quentin <qle@odoo.com> | 2021-05-10 14:11:59 +0000 |
| commit | 8c584aa86518565a652daf71e3d1824af1fb867a (patch) | |
| tree | d85413f37c2d2689cb4ea71037d83ec30aa7b6e7 | |
| parent | edffdd10f3ceb3826bf8897f93fa8290d7fce1ec (diff) | |
[IMP] hw_drivers: Document pitfalls of update_iot_devices logic
closes odoo/odoo#70079
Related: odoo/enterprise#18034
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
| -rw-r--r-- | addons/hw_drivers/interface.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/addons/hw_drivers/interface.py b/addons/hw_drivers/interface.py index c1ccc50fd99..dbecbbf4723 100644 --- a/addons/hw_drivers/interface.py +++ b/addons/hw_drivers/interface.py @@ -36,6 +36,15 @@ class Interface(Thread, metaclass=InterfaceMetaClass): def update_iot_devices(self, devices={}): added = devices.keys() - self._detected_devices removed = self._detected_devices - devices.keys() + # keys() returns a dict_keys, and the values of that stay in sync with the + # original dictionary if it changes. This means that get_devices needs to return + # a newly created dictionary every time. If it doesn't do that and reuses the + # same dictionary, this logic won't detect any changes that are made. Could be + # avoided by converting the dict_keys into a regular dict. The current logic + # also can't detect if a device is replaced by a different one with the same + # key. Also, _detected_devices starts out as a class variable but gets turned + # into an instance variable here. It would be better if it was an instance + # variable from the start to avoid confusion. self._detected_devices = devices.keys() for identifier in removed: |
