Warn on non-string config entry unique IDs (#125662)

* Warn on non-string config entry unique IDs

* Add comment

* isinstance
This commit is contained in:
epenet 2024-09-10 15:30:03 +02:00 committed by GitHub
parent 67dc870e52
commit 97c55ae6f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -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
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):
unique_id_hash = str(entry.unique_id) # type: ignore[unreachable]
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
)

View file

@ -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