Skip to content

Avoid mutating shared restore attribute lists - #1574

Merged
Ernst79 merged 1 commit into
custom-components:masterfrom
IoannisArmamentos:fix/restore-attributes-mutation
Sep 8, 2026
Merged

Avoid mutating shared restore attribute lists#1574
Ernst79 merged 1 commit into
custom-components:masterfrom
IoannisArmamentos:fix/restore-attributes-mutation

Conversation

@IoannisArmamentos

Copy link
Copy Markdown
Contributor

Summary

Avoid mutating the shared RESTORE_ATTRIBUTES lists when restoring entity state.

Problem

Several restore paths assigned RESTORE_ATTRIBUTES directly to a local variable and then appended another attribute to it.

Because lists are mutable, this modified the shared module-level list in place.

The most significant occurrence was in device_tracker.data_update(), where the mutation could happen repeatedly during normal BLE updates and continuously add duplicate entries for the lifetime of Home Assistant.

The same pattern was also present in the one time restore paths for device tracker, sensor, and binary sensor entities.

Fix

Create a new list containing the base restore attributes plus the entity-specific mac_address or uuid attribute instead of appending to the shared list.

Restore behavior and attribute ordering remain unchanged, while RESTORE_ATTRIBUTES itself is no longer modified.

@Ernst79 Ernst79 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Ernst79
Ernst79 merged commit 5c264c6 into custom-components:master Sep 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants