Skip to content

Commit b4c645c

Browse files
committed
fix: rebuild BackupManager when settings instance changes
Test fixtures that monkeypatch ENABLE_AUTO_BACKUP and reset the global settings singleton get a new Settings instance back from get_global_settings(). The cached BackupManager on the client object holds a reference to the old (pre-reset) settings, so its 'enabled' property keeps returning False even after the toggle is flipped. get_backup_manager now compares mgr._settings is settings; mismatch forces a rebuild. Production never hits this path (the settings singleton is built once at startup); tests get a fresh manager after each toggle.
1 parent 8af7dc5 commit b4c645c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/ha_mcp/backup_manager.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,15 @@ def get_backup_manager(client: Any, settings: Any) -> BackupManager:
435435
"""Get-or-create the singleton BackupManager attached to ``client``.
436436
437437
Stored on the client object so tools that share a client share one
438-
manager (and one set of per-entity locks).
438+
manager (and one set of per-entity locks). Rebuilds when the
439+
``settings`` object identity differs from the cached manager's —
440+
runtime env-var changes that reset the global settings singleton
441+
(see ``config._reset_global_settings``) yield a fresh ``settings``
442+
instance, which forces a manager rebuild so the new
443+
``enable_auto_backup`` / throttle / retention values take effect.
439444
"""
440445
mgr = getattr(client, "_auto_backup_manager", None)
441-
if mgr is None:
446+
if mgr is None or mgr._settings is not settings:
442447
mgr = BackupManager(settings, client)
443448
register_default_handlers(mgr, client)
444449
try:

0 commit comments

Comments
 (0)