From 97c55ae6f1095216df49fb3f7078055e80e81f18 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:30:03 +0200 Subject: [PATCH] Warn on non-string config entry unique IDs (#125662) * Warn on non-string config entry unique IDs * Add comment * isinstance --- homeassistant/config_entries.py | 11 +++++++---- tests/test_config_entries.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index e64d2001efa..7870964722f 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1527,10 +1527,13 @@ class ConfigEntryItems(UserDict[str, ConfigEntry]): self._domain_index.setdefault(entry.domain, []).append(entry) if entry.unique_id is not None: unique_id_hash = entry.unique_id - # Guard against integrations using unhashable unique_id - # In HA Core 2024.9, we should remove the guard and instead fail - if not isinstance(entry.unique_id, Hashable): - unique_id_hash = str(entry.unique_id) # type: ignore[unreachable] + if not isinstance(entry.unique_id, str): + # Guard against integrations using unhashable unique_id + # In HA Core 2024.9, we should remove the guard and instead fail + if not isinstance(entry.unique_id, Hashable): # type: ignore[unreachable] + unique_id_hash = str(entry.unique_id) + # Checks for other non-string was added in HA Core 2024.10 + # In HA Core 2025.10, we should remove the error and instead fail report_issue = async_suggest_report_issue( self._hass, integration_domain=entry.domain ) diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index d01febd6904..abe8ab83952 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -5093,7 +5093,7 @@ async def test_hashable_non_string_unique_id( entries[entry.entry_id] = entry assert ( "Config entry 'title' from integration test has an invalid unique_id" - ) not in caplog.text + ) in caplog.text assert entry.entry_id in entries assert entries[entry.entry_id] is entry