Module 'homeassistant.components.mqtt' has no attribute 'util'

Hello

My MQTT integrations stopped working, and looking at the logs I see

Traceback (most recent call last):
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/config_entries.py", line 365, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/__init__.py", line 480, in async_setup_entry
    await async_forward_entry_setup_and_setup_discovery(entry)
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/__init__.py", line 447, in async_forward_entry_setup_and_setup_discovery
    from . import device_automation, tag
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/device_automation.py", line 8, in <module>
    from . import device_trigger
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/device_trigger.py", line 28, in <module>
    from . import debug_info, trigger as mqtt_trigger
  File "/home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/trigger.py", line 23, in <module>
    vol.Required(CONF_TOPIC): mqtt.util.valid_subscribe_topic_template,
AttributeError: module 'homeassistant.components.mqtt' has no attribute 'util'

I had a similar issue (this one, linked to this github issue), but it was solved by simply installing paho-mqtt manually. Now I tried to install and then even to update it (with . /home/homeassistant/pyenv-activate.sh; exec pip3 install -U paho-mqtt), but last time this solved the issue, now it didn’t.

Is there any similar issue now? How can it be solved?

It may be the case that the MQTT component in HA is missing a file named util.py.
One way to check is to do ls /home/homeassistant/.pyenv/versions/3.9.15/lib/python3.9/site-packages/homeassistant/components/mqtt/ and see if the file util.py is there.

Thank you for your message

Actually the file is present, and it has the same permissions as trigger.py:

-rw-r--r--    1 homeassistant homeassistant  3312 30 ott 09.54 trigger.py
-rw-r--r--    1 homeassistant homeassistant  4140 30 ott 09.54 util.py

Issue solved; I “cloned” the virtual environment and started poking around. The missing package was numpy, so I installed it through . /home/homeassistant/pyenv-activate.sh; exec pip3 install numpy and now everything works again.

It’s a bit difficult to find out exactly what is the issue; aren’t there ways to detect missing dependencies easier? It’s strange to me that a missing library gives an error so unrelated to the core issue. Maybe there is some message filtering, but this leads to higher effort needed when an issue arises.

Or maybe the logs I’m checking (registers from the frontend) are not the correct ones…