Skip to content

Make profile import atomic and stop it wiping other profiles' data - #2616

Merged
m3nu merged 1 commit into
masterfrom
fix/2602-atomic-profile-import
Nov 15, 2026
Merged

m3nu merged 1 commit into
masterfrom
fix/2602-atomic-profile-import

Conversation

@m3nu

@m3nu m3nu commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Description

ProfileExport.to_db now 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.

  • One transaction. Every DB write runs inside DB.atomic('IMMEDIATE'). The profile row is saved before its child rows, so an unknown field fails before anything else is written. IMMEDIATE matters 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.
  • Keyring after commit. The repo password is written only once the transaction has committed, and a keyring failure is logged and no longer aborts the import. The keyring is still selected at the start of to_db, as before.
  • Wi-Fi rules, sources and exclusions are replaced for the imported profile only: exported row ids are dropped, profile is 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.
  • Absent is not empty. When overwriting an existing profile, a section missing from the file leaves that profile's rows alone; an empty list clears them. Exports from before v0.11.4 have no ExclusionModel, and hand-written ~/.vorta-init.json files often have no settings sections.
  • Settings are updated by key. Nothing is dropped or inserted, so settings that are not in the file keep their current values.
  • No mutation of the export. to_db works on a copy of the dict. This also fixes the import dialog's "Schema upgrade failure" message: to_db used to delete SchemaVersion, and the dialog's handler then died on KeyError before it could show anything.
  • from_db exports Wi-Fi rows without id.

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

  • Wi-Fi rules are imported with the profile regardless of "Overwrite existing settings". Before, they were silently dropped when the box was unchecked. Overwriting an existing profile with the box unchecked therefore now replaces that profile's Wi-Fi rules, like its sources and exclusions.
  • use_system_keyring and internal UI state are never imported (previous_profile_id, window size, sort and display-mode keys; every setting of type internal). This also applies to ~/.vorta-init.json. Importing use_system_keyring together with a password was already broken: the password went to the backend chosen before the setting changed. autostart is still imported (Autostart setting not set after importing settings from .vorta-init.json  #1092).
  • Settings missing from the import file are no longer reset to defaults.
  • A file without SourceFileModel now imports. It raised KeyError before.
  • A new profile never inherits child rows orphaned under its id by an earlier failed import; those rows are removed.
  • An export with "password": null (written when no passphrase is stored) now imports. It raised AttributeError before.

Not included: a failed bootstrap import on an install without profiles still crashes startup. That is in application.py and 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 real to_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 with IMMEDIATE.
  • The tests that target the bugs were confirmed to fail on the previous to_db.
  • uv run pytest tests/unit --ignore=tests/unit/test_keyring_darwin.py on macOS: 382 passed, 7 skipped.
  • Not run locally: the nox matrix across Borg versions and the integration tests. The change does not depend on Borg.
  • All new tests mock the keyring. Lock contention was checked by hand with a second SQLite connection holding the write lock (the import waits for the busy timeout, raises OperationalError and leaves the DB unchanged), not with a real Borg job thread.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have read the CONTRIBUTING guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.

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
@m3nu
m3nu merged commit 21b4960 into master Nov 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make profile import atomic and stop it wiping other profiles' data

1 participant