Refactor/session for path - #963
Merged
Merged
Conversation
…enSAK-Org#956) After rebasing onto beta, GsakImportWorker still referenced the removed original_path, and recalculate_distances()/distances_up_to_date() assumed the global engine had been switched to db_path. With session_for() it no longer is, so a non-active target's distances would have been computed from and written to the active database. - database: _session_on(db_path) picks get_session() for the active DB and session_for() otherwise; the distance helpers use it. - gsak_import_dialog: update distances of target_db_path or the active DB. - Narrow Optional paths for session_for() and fix the Engine annotation in importer (mypy clean). - test: patch session_for instead of init_db. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nagisml
added a commit
to nagisml/OpenSAK
that referenced
this pull request
Oct 5, 2026
…stance-followups - distances_up_to_date(): use _session_on(db_path), keep index comment - GsakImportWorker.run(): busy progress and _invalidate_distances() on target_path in the session_for()-based run() - test: stub session_for instead of the removed init_db switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #957: don't swap the global DB engine from worker threads
Background jobs that work on a database other than the active one (GSAK import, GPX/zip import, move/copy caches, PQ e-mail import) used to call
init_db()from the worker thread to switch the app-wide engine, and switch it back afterwards. While that ran, anything on the GUI thread that calledget_session()(timers, queued signals) could read from or write to the wrong database. A multi-database GSAK import now does this several times in a row.Changes
session_for(db_path)indb/database.py: a private engine and session for one database, with the schema migrated exactly likeinit_db()does. The global engine is never touched.session_for()for a non-active target, andget_session()as before when the target is the active database.recalculate_distances,distances_up_to_date) open a private session whendb_pathisn't the active database. Without this, the in-worker distance update from Fixing 955 #956 would have written a non-active target's distances into the active database.Testing
session_for, plus worker tests that fail if the active session orinit_db()is used for another database.