[BUG] Circular Import Dependencies Breaking AppDaemon Latest Version
Bug report
Description
ControllerX fails to load with the latest version of AppDaemon due to circular import dependencies. AppDaemon now uses stricter dependency resolution with Python's graphlib topological sorting, which detects and rejects circular imports that were previously tolerated.
Additional information
- AppDaemon version: 4.5.12
- ControllerX version: 5.0.0
Error Message
graphlib.CycleError: ('nodes are in a cycle', ['cx_core.type_controller', 'cx_core.type.cover_controller', 'cx_core', 'cx_core.controller', 'cx_core.type_controller'])
Additional cycles detected:
['cx_core.type.media_player_controller', 'cx_core', 'cx_core.controller', 'cx_core.type.media_player_controller'] ['cx_core', 'cx_core.release_hold_controller', 'cx_core'] ['cx_core', 'cx_core.release_hold_controller', 'cx_core.type.light_controller', 'cx_core'] ...
Additional Context
This issue was introduced when AppDaemon added stricter dependency checking using Python's graphlib module. While the circular dependencies always existed, they were previously tolerated. The new strict checking is actually correct behavior - relative imports are Python best practice for intra-package imports.
References
Python documentation on relative imports: https://docs.python.org/3/reference/import.html#package-relative-imports graphlib.TopologicalSorter: https://docs.python.org/3/library/graphlib.html
Using exclude_dirs as directed in the documentation solve the issue
appdaemon: app_dir: /config/apps ... exclude_dirs:
- cx_core
I confirm the problem with version 0.17.11 of the add-on; ControlerX does not start. Restored to 0.17.10 and it's OK.
Using exclude_dirs as directed in the documentation solve the issue
appdaemon: app_dir: /config/apps ... exclude_dirs:
- cx_core
FWIW this didn't solve it for me unfortunately - had to downgrade AppDaemon to 0.17.10, at which point ControllerX started working fine again.
I think this might've resolved itself with either AppDaemon 0.17.12 or 0.17.13 - I just tried upgrading from 0.17.10 to 0.17.13 and ControllerX appears to still be working as expected. Is anyone else able to confirm the same?
Still the same error messages for me when I tried 0.17.13 without the exclude_dirs: cx_core workaround
File "/usr/lib/python3.12/site-packages/appdaemon/dependency.py", line 224, in topo_sort
return list(ts.static_order())
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/graphlib.py", line 244, in static_order
self.prepare()
File "/usr/lib/python3.12/graphlib.py", line 106, in prepare
raise CycleError(f"nodes are in a cycle", cycle)
graphlib.CycleError: ('nodes are in a cycle', ['cx_core', 'cx_core.release_hold_controller', 'cx_core.type.media_player_controller', 'cx_core'])
I've lost brightness press-and-hold controls etc. with this workaround, is that the expected behaviour?
Or is there something else I should be doing with the workaround to regain all prior functionality? Thanks.
How strange. Everything appears to be working fine again for me with 0.17.13 after nothing worked on 0.17.11 (in both cases with exclude_dirs: ... - cx_core in place - already had that in my config).
Maybe it's got something to do with which controller(s) or integration(s) are in use.
All of my lightswitches are broken, and my wife is not happy. I've added exclude_dirs but it doesn't seem to help. It was all working properly untill I did a big upgrade a few days ago after leaving my Home Assistant instance alone for several months. Seems the easiest fix is downgrading AppDaemon. I'm currently running version 0.17.13 as a Home Assistant addon. How do you guys downgrade AppDaemon?
How do you guys downgrade AppDaemon?
Assuming you backed up AppDaemon 0.17.10 as part of upgrading it (option on the upgrade screen), the easiest way is to go to Settings -> System -> Backups -> "xx add-on update backups", click on "AppDaemon 0.17.10" in the list, tick the box next to "Add-ons -> AppDaemon (0.17.10)", and finally click Restore.