Repository navigation
Make profile import atomic and stop it wiping other profiles' data - #2616
Merged
Merged
Conversation
ProfileExport.to_db imported one profile but rewrote install-wide data without a transaction. With "Overwrite existing settings" it dropped the Wi-Fi and settings tables, so every other profile lost its Wi-Fi rules, the imported rules kept the exporter's profile id, and settings missing from the file fell back to defaults. A failure late in the import left the repo row, keyring entry, orphan sources and the emptied tables behind. Run all writes in one IMMEDIATE transaction on a copy of the export dict, save the profile before its children, and write the keyring password only after the commit. Wi-Fi rules, sources and exclusions are replaced for the imported profile only, with ids stripped and the profile id remapped, and only when the section is present in the file. Wi-Fi rules now travel with the profile regardless of the settings checkbox. Settings are updated by key instead of drop and recreate; internal UI state and use_system_keyring are never imported. Not mutating the export dict also revives the dialog's "Schema upgrade failure" message, which died on a KeyError before. Fixes #2602
5 of 9 tasks
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.
Description
ProfileExport.to_dbnow imports a single profile without touching data that belongs to other profiles or to the install, and either completes or leaves the database as it was.DB.atomic('IMMEDIATE'). The profile row is saved before its child rows, so an unknown field fails before anything else is written.IMMEDIATEmatters because the import reads before it writes: with a deferred transaction, a Borg job thread committing in between makes the first write fail at once with "database is locked", without waiting for the busy timeout.to_db, as before.profileis set to the imported profile's id, and only that profile's rows are deleted. The Wi-Fi table is no longer dropped and recreated.ExclusionModel, and hand-written~/.vorta-init.jsonfiles often have no settings sections.to_dbworks on a copy of the dict. This also fixes the import dialog's "Schema upgrade failure" message:to_dbused to deleteSchemaVersion, and the dialog's handler then died onKeyErrorbefore it could show anything.from_dbexports Wi-Fi rows withoutid.Related Issue
Fixes #2602
Motivation and Context
See the issue for the four bugs. In short, importing any profile with "Overwrite existing settings" checked (the default) deleted every other profile's Wi-Fi rules, attached the imported rules to whichever profile had the exporter's id, and reset settings absent from the file. A failed import left a repo row, a keyring entry, orphan sources and the emptied tables behind.
Behaviour changes to be aware of
use_system_keyringand internal UI state are never imported (previous_profile_id, window size, sort and display-mode keys; every setting of typeinternal). This also applies to~/.vorta-init.json. Importinguse_system_keyringtogether with a password was already broken: the password went to the backend chosen before the setting changed.autostartis still imported (Autostart setting not set after importing settings from .vorta-init.json  #1092).SourceFileModelnow imports. It raisedKeyErrorbefore."password": null(written when no passphrase is stored) now imports. It raisedAttributeErrorbefore.Not included: a failed bootstrap import on an install without profiles still crashes startup. That is in
application.pyand tracked in #2615.How Has This Been Tested?
tests/unit/test_import_export.py: 27 tests pass (16 new or changed). They cover rollback on an unknown profile key and on a failure mid-transaction, the dialog path through the realto_db, Wi-Fi remapping for new and overwritten profiles, absent sections on both paths, the settings merge and skip set, autostart reaching its hook, the password being written outside the transaction, a keyring failure keeping the profile, an export/import round trip, and that the transaction is opened withIMMEDIATE.to_db.uv run pytest tests/unit --ignore=tests/unit/test_keyring_darwin.pyon macOS: 382 passed, 7 skipped.OperationalErrorand leaves the DB unchanged), not with a real Borg job thread.Types of changes
Checklist:
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.