core: 'Setup failed for dhcp' in 2023.4 and 2023.4.1

The problem

I have 3 errors (included below) relating to this in the log and cannot use integrations relying on the import (ESPHome and Broadlink, in this case)

After updating to 2023.4, everything was initially fine. A few hours later I restarted Home Assistant, that was when I first saw this issue. I didn’t log anything as I didn’t have time to investigate until now.

I just updated to 2023.4.1 and the issue was fixed. Then I restarted again, and the issue is back.

What version of Home Assistant Core has the issue?

2023.4.1

What was the last working version of Home Assistant Core?

2023.3.6

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

# LOGS (from GUI)

Logger: homeassistant.setup
Source: setup.py:213
First occurred: 01:23:59 (1 occurrences)
Last logged: 01:23:59
Setup failed for dhcp: Unable to import component: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)

Logger: homeassistant.setup
Source: setup.py:203
First occurred: 01:24:23 (1 occurrences)
Last logged: 01:24:23
Unable to set up dependencies of default_config. Setup failed for dependencies: dhcp

Logger: homeassistant.setup
Source: setup.py:205
First occurred: 01:24:23 (1 occurrences)
Last logged: 01:24:23
Setup failed for default_config: (DependencyError(...), 'Could not setup dependencies: dhcp')

# STACK TRACES

2023-04-07 01:32:34.550 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration esphome: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)
2023-04-07 01:32:34.550 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2042, in _load_integration
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 779, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 796, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/esphome/config_flow.py", line 21, in <module>
    from homeassistant.components import dhcp, zeroconf
  File "/usr/src/homeassistant/homeassistant/components/dhcp/__init__.py", line 19, in <module>
    from aiodiscover import DiscoverHosts
  File "/usr/local/lib/python3.10/site-packages/aiodiscover/__init__.py", line 9, in <module>
    from .discovery import DiscoverHosts  # noqa: F401
  File "/usr/local/lib/python3.10/site-packages/aiodiscover/discovery.py", line 13, in <module>
    from dns.message import Message, QueryMessage
ImportError: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 840, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 858, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 957, in async_create_flow
    await _load_integration(self.hass, handler_key, self._hass_config)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2049, in _load_integration
    raise data_entry_flow.UnknownHandler
homeassistant.data_entry_flow.UnknownHandler
2023-04-07 01:26:05.631 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration esphome: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)
2023-04-07 01:26:05.634 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration esphome: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)
2023-04-07 01:26:05.651 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration esphome: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)
2023-04-07 01:36:41.639 ERROR (MainThread) [homeassistant.config_entries] Error importing platform config_flow from integration broadlink to set up broadlink configuration entry: cannot import name 'QueryMessage' from 'dns.message' (/usr/local/lib/python3.10/site-packages/dns/message.py)

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 39 (10 by maintainers)

Most upvoted comments

Upgrade dnspython to 2.3.0

Thank you, this seems to have resolved it for now.

For anyone else with the same issue:

user@host:~$ docker exec -it homeassistant bash
bash-5.1# pip3 install --upgrade dnspython==2.3.0

I believe I’ve tracked down the issue that was affecting me. It was a custom integration - minecraft server status (but not yours @jdeath, but thanks for the pointer). A long time ago I must have manually added the integration (there is now one in core) and it was using an old mcstatus dependency.

A useful debug tool to track down dependencies might be to install pipdeptree inside the homeassistant container:

# get inside the container
docker exec -it homeassistant bash
# install pipdeptree and run it
pip install pipdeptree
pipdeptree

That will output all packages and dependencies, and you can look for what is using dnspython3. In my case I saw:

mcstatus==5.1.1
├── asyncio-dgram [required: >=1.2.0, installed: 2.1.2]
├── click [required: >=7.1.1, installed: 8.1.6]
├── dnspython3 [required: >=1.15.0, installed: 1.15.0]
│   └── dnspython [required: ==1.15.0, installed: 2.3.0]
└── six [required: >=1.14.0, installed: 1.16.0]

It might then be useful to search for references to that package, something like:

find / -xdev -type f -print0 | xargs -0 grep -H "mcstatus"

But thanks to @jdeath I already suspected something minecrafty and found the old custom component (this wasn’t installed via HACS so I wasn’t spotting it previously and had to delete it manually).

@energywave The latest update I pushed a few days ago should fix the problem. It now uses the same mcstatus version as built-in integration. No reason to update past the one used by home assistant as that could cause other issues. The issue should be gone after upgrading and restarting homeassistant a couple times.

This is still an issue for 2023.4.2 , although it did not show up again until a few restarts. Weird! Opps. I didn’t see this could be a custom component issue. Anyone with this issue happen to use my minecraft custom_component that adds bedrock support? After some digging, it has a pinned mcstatus, which requires dnspython3, which requires dnspython. I’ll try update that to be in line with current versions.

@JBP77 Install the “SSH & Web Terminal” addon. turn off protection mode, ssh in and type (it is in a few posts higher):

user@host:~$ docker exec -it homeassistant bash
bash-5.1# pip3 install --upgrade dnspython==2.3.0

Upgrade dnspython to 2.3.0