mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
Saving zims.yaml keeps the entries of Zims the database does not have yet (#935)
A rebuilt database imports zims.yaml before the refresh has modeled a single Zim. That import has no database version to compare with, so it saves the config afterward, and the save wrote only the Zims in the database: none. The file's choices were erased and every Zim was then modeled with the default. The dump now starts from the file's entries and overlays the database's, so a choice survives until its Zim is modeled again, and a Zim in the database still decides its own line. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c0452e29e6
commit
5be899bf1f
2 changed files with 34 additions and 2 deletions
|
|
@ -843,11 +843,14 @@ class ZimsConfig(ConfigFile):
|
|||
raise
|
||||
|
||||
def dump_config(self, file: pathlib.Path = None, send_events=False, overwrite=False):
|
||||
"""Save every Zim's settings. Of several versions of one Zim, the newest decides."""
|
||||
"""Save every Zim's settings. Of several versions of one Zim, the newest decides.
|
||||
|
||||
The file's entries for Zims the database does not have are kept: a rebuilt database imports this config
|
||||
(and saves it) before the refresh has modeled a single Zim, and the choices must survive until then."""
|
||||
with get_db_session() as session:
|
||||
version = self.db_version_for_dump(session)
|
||||
auto_search = self.auto_search
|
||||
# Sorted by path, so the newest version of a Zim (its date sorts last) wins.
|
||||
auto_search = dict()
|
||||
for zim in session.query(Zim).order_by(Zim.path):
|
||||
auto_search[zim_config_name(zim.path)] = bool(zim.auto_search)
|
||||
self._config['auto_search'] = dict(sorted(auto_search.items()))
|
||||
|
|
|
|||
|
|
@ -97,3 +97,32 @@ async def test_older_file_saves_the_database(test_session, test_directory, async
|
|||
data = config.read_config_file()
|
||||
assert data['auto_search'] == {'wikipedia_en_all_maxi': False}
|
||||
assert data['version'] > saved_version
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dump_keeps_zims_the_database_does_not_have(test_session, test_directory, async_client,
|
||||
test_wrolpi_config, zim_path_factory):
|
||||
"""A rebuilt database imports zims.yaml before any Zim is modeled, then saves the config (an import without a
|
||||
known version does). That save must keep the file's choices for Zims not yet in the database, or the refresh
|
||||
that follows models every Zim with the default."""
|
||||
config = lib.get_zims_config()
|
||||
config.write_config_data(dict(version=3, auto_search={'wikiversity_en_all_maxi': False, 'ham': True}),
|
||||
config.get_file())
|
||||
assert test_session.query(Zim).count() == 0, 'The database is empty, as after a rebuild'
|
||||
|
||||
config.import_config()
|
||||
config.dump_config()
|
||||
assert config.read_config_file()['auto_search'] == {'ham': True, 'wikiversity_en_all_maxi': False}, \
|
||||
'The dump kept the file entries for Zims the database does not have'
|
||||
|
||||
# The refresh models the Zims afterward; the choice is applied.
|
||||
file_group = FileGroup.from_paths(test_session, zim_path_factory('wikiversity_en_all_maxi_2026-05.zim'))
|
||||
zim = lib.model_zim(file_group, test_session)
|
||||
test_session.commit()
|
||||
assert zim.auto_search is False
|
||||
|
||||
# A Zim in the database overrides the file's stale value for its name.
|
||||
zim.auto_search = True
|
||||
test_session.commit()
|
||||
config.dump_config()
|
||||
assert config.read_config_file()['auto_search'] == {'ham': True, 'wikiversity_en_all_maxi': True}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue