wrolpi/wrolpi/collections
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
..
test Remove code that only tests called (#888) 2026-10-27 16:00:27 -06:00
__init__.py Add ordered collections (playlists): polymorphic items + item API (#475) 2026-06-11 19:46:34 -06:00
api.py Reorganize conflicts and no-move reorganize wait for a concurrent writer (#847) 2026-10-20 17:16:17 -06:00
config.py A config import records the version of the file it read (#897) 2026-10-27 21:03:52 -06:00
errors.py Add ordered collections (playlists): polymorphic items + item API (#475) 2026-06-11 19:46:34 -06:00
lib.py Other search tab: search Channels by name, add Domains and Playlists, fix the estimate (#785) 2026-10-07 18:22:12 -06:00
models.py Remove code that only tests called (#888) 2026-10-27 16:00:27 -06:00
reorganize.py Reorganize conflicts and no-move reorganize wait for a concurrent writer (#847) 2026-10-20 17:16:17 -06:00
schema.py Remove unused code found by vulture (#885) 2026-10-27 15:50:09 -06:00
sync.py Add ordered collections (playlists): polymorphic items + item API (#475) 2026-06-11 19:46:34 -06:00
types.py Add a Repos module that mirrors git repositories (#783) 2026-10-07 15:16:58 -06:00