wrolpi/modules
lrnselfreliance ce7095c0a1
A config import records the version of the file it read (#897)
* A config import records the version of the file it read

Every Sanic process initializes the configs it shares with the others while one of them imports the
database configs.  `ConfigFile.initialize` reset the shared dict to the defaults (version 0) before
loading the file, and the import read the file's version from that shared dict.  When the two
overlapped, the import recorded version 0 in `config_version`; every later save of that config was
refused as older than its file, and the next startup's import undid the unsaved changes.

- `ConfigFile.initialize` sets the shared dict in one call, and `MultiFileConfig.initialize` no longer
  empties it first, so other processes never see the defaults in place of the file.
- An import reads the version and rows from the file it read (`import_file_config`), never the shared
  dict.

Tests run the race for every config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Playlists import steps read the file's config; tests restore switch handlers

- `PlaylistsConfig._keep_unreadable_items` and `_merge_items` read `import_file_config`, not the
  shared `_config`.
- `test_import_steps_read_the_file`: no versioned config's `prepare`/`after_import` (or the methods
  they call) reads the shared config.
- The new tests create configs, which replaced the global configs' switch handlers for later tests
  (repos tests then dumped a test's config).  `restore_switch_handlers` puts them back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Only the first process loads a shared config; the others attach

A restarted perpetual process initializes the configs while the other processes serve them.
Re-loading the files then reverted or dropped newer changes in the shared dict (an inventory
created or saved since, a config updated but not saved yet).

- `ConfigFile.initialize` loads the file only into an empty shared dict, under
  `config_update_lock`; otherwise it keeps what the dict holds.
- `MultiFileConfig.initialize` imports only into an empty shared store, under `save_lock()`, and
  points `_configs` back at the shared store if the import fails.
- `MultiFileConfig.create` checks for the slug and inserts it under `save_lock()`.

`test_initialize_keeps_the_shared_config` now changes the shared config between two processes'
initializes (an inventory renamed and another created), and requires the second to keep it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 21:03:52 -06:00
..
archive A malformed entry stops a backup preview or merge with an error naming it (#896) 2026-10-27 20:59:49 -06:00
docs Remove unused code found by vulture (#885) 2026-10-27 15:50:09 -06:00
flasher Configs without database rows read and validate only; imports run off the event loop (#874) 2026-10-25 15:17:31 -06:00
inventory Remove unused code found by vulture (#885) 2026-10-27 15:50:09 -06:00
map Map downloads compare a Download's region with SQLite's JSON operator (#894) 2026-10-27 18:58:19 -06:00
repos A malformed entry stops a backup preview or merge with an error naming it (#896) 2026-10-27 20:59:49 -06:00
videos A config import records the version of the file it read (#897) 2026-10-27 21:03:52 -06:00
zim Remove code that only tests called (#888) 2026-10-27 16:00:27 -06:00
__init__.py Add a Repos module that mirrors git repositories (#783) 2026-10-07 15:16:58 -06:00