From eb824894261a750c598d6eed65f28bc6a446ce5c Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Sun, 25 Oct 2026 19:56:30 -0600 Subject: [PATCH] Keep playlists.yaml in shared memory so the perpetual process can save it (#881) playlists_config was the only config not attached to a shared_ctx dict. Switches save configs in the perpetual process, which never imports the files, so its playlists_config kept the default version 0. While the database had no version row for playlists.yaml, the dump wrote version 1 and `save` refused to overwrite the newer file; the refused save never recorded the row, so every later save was refused too, and new playlists never reached the config. Co-authored-by: Claude Opus 5.5 --- wrolpi/contexts.py | 8 ++++++++ wrolpi/test/test_contexts.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/wrolpi/contexts.py b/wrolpi/contexts.py index 55559427..99c7bf9e 100644 --- a/wrolpi/contexts.py +++ b/wrolpi/contexts.py @@ -34,6 +34,7 @@ def attach_shared_contexts(app: Sanic): app.shared_ctx.videos_downloader_config = manager.dict() app.shared_ctx.domains_config = manager.dict() app.shared_ctx.repos_config = manager.dict() + app.shared_ctx.playlists_config = manager.dict() app.shared_ctx.archive_downloader_config = manager.dict() app.shared_ctx.download_cache_config = manager.dict() app.shared_ctx.map_pins_config = manager.dict() @@ -130,6 +131,7 @@ def reset_shared_contexts(app: Sanic): app.shared_ctx.videos_downloader_config.clear() app.shared_ctx.domains_config.clear() app.shared_ctx.repos_config.clear() + app.shared_ctx.playlists_config.clear() app.shared_ctx.archive_downloader_config.clear() app.shared_ctx.download_cache_config.clear() # Shared dicts. @@ -304,6 +306,12 @@ def initialize_configs_contexts(app: Sanic): except Exception as e: logger.error(f'Failed to initialize in-memory repos config: {e}') + try: + from wrolpi.collections.config import playlists_config + playlists_config.initialize(app.shared_ctx.playlists_config) + except Exception as e: + logger.error(f'Failed to initialize in-memory playlists config: {e}') + try: from modules.archive.lib import ARCHIVE_DOWNLOADER_CONFIG ARCHIVE_DOWNLOADER_CONFIG.initialize(app.shared_ctx.archive_downloader_config) diff --git a/wrolpi/test/test_contexts.py b/wrolpi/test/test_contexts.py index 35239010..d0c8e6ed 100644 --- a/wrolpi/test/test_contexts.py +++ b/wrolpi/test/test_contexts.py @@ -38,3 +38,21 @@ def test_domains_config_in_shared_context(): for config_name in expected_configs: assert hasattr(test_app.shared_ctx, config_name), \ f"{config_name} not found in shared_ctx" + + +def test_all_configs_in_shared_context(): + """Every config keeps its in-memory data in shared memory. Switches save configs in the perpetual process, which + does not import the files; a config with process-local data would save a stale version there.""" + from multiprocessing.managers import DictProxy + + from sanic import Sanic + from wrolpi.common import get_all_configs + from wrolpi.contexts import attach_shared_contexts, initialize_configs_contexts + + test_app = Sanic(f"test_context_{id(test_all_configs_in_shared_context)}") + attach_shared_contexts(test_app) + initialize_configs_contexts(test_app) + + not_shared = sorted(name for name, config in get_all_configs().items() + if not isinstance(getattr(config, '_config', None), DictProxy)) + assert not_shared == [], 'Add these configs to attach_shared_contexts() and initialize_configs_contexts()'