Skip to content

Commit

Permalink
Warn on non-string config entry unique IDs (#125662)
Browse files Browse the repository at this point in the history
* Warn on non-string config entry unique IDs

* Add comment

* isinstance
  • Loading branch information
epenet authored Sep 10, 2024
1 parent 67dc870 commit 97c55ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,10 +1527,13 @@ def _index_entry(self, entry: ConfigEntry) -> None:
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
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97c55ae

Please sign in to comment.