Skip to content

Don't save or re-arm the schedule when a profile is loaded - #2620

Merged
m3nu merged 1 commit into
masterfrom
fix/2611-schedule-populate-signals
Nov 15, 2026
Merged

m3nu merged 1 commit into
masterfrom
fix/2611-schedule-populate-signals

Conversation

@m3nu

@m3nu m3nu commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Description

Loading a profile into the schedule page no longer saves anything or re-arms a timer.

  • SchedulePage.populate_from_profile sets the interval unit, interval count and fixed time inside QtCore.QSignalBlocker context managers, so on_scheduler_change does not run while the widgets still hold a mix of the previous and the new profile's values. The radio buttons are deliberately not blocked: their toggled signal enables and disables the two frames, and setChecked() does not emit clicked, which is the signal that saves.
  • hasPopulatedScheduleFields is removed. It was added in fix: Delay updating schedule until after fields have been initialized #2317 for on_scheduler_change callback causes race conditions in updating BackupProfile, causing spurious catch-up runs #2316, the startup variant of the same bug, and only covered the first populate in __init__. With the setters blocked on every populate it has nothing left to do.
  • MainWindow.profile_imported_event now calls scheduler.set_timer_for_profile() for the imported profile. Until now, importing over the selected profile re-armed its timer only as a side effect of the populate. The call sits before the confirmation dialog, so the timer for the old schedule is not live while the dialog is open.

QSignalBlocker as a context manager is new in this codebase; the other sites use blockSignals(True) / blockSignals(False) pairs. It is used here because it covers three widgets without nesting and unblocks when a setter raises. The existing sites are not changed.

Related Issue

Fixes #2611

Motivation and Context

Switching the selected profile fired on_scheduler_change once per setter that changed a value. Each call wrote all schedule widgets to the newly selected profile and re-armed its timer from that row. With profile A at "every 1 day" and profile B at "every 12 hours", selecting B first saved "every 1 hour" to B. If B's last backup was more than an hour ago and "Run missed backups" was on, a catch-up backup of B started.

Deleting and renaming a profile go through the same code and were further triggers: deleting a profile populated its neighbour while the widgets still held the deleted profile's values, saved the mixed row to the neighbour and could start a catch-up backup of it.

Behaviour changes to be aware of

  • Switching, deleting or renaming a profile no longer saves the schedule, re-arms the timer or emits schedule_changed. The "next backup" label is still redrawn from the scheduler's state.
  • Import arms the imported profile at once, for every import, not only for an overwrite of the selected profile. Before, a profile imported as new, or over a profile that was not selected, got its timer at the next 15-minute reload. If a catch-up is due under the imported schedule, it now starts before the "Profile import successful" dialog is dismissed. Before, it started right after the dialog or at the next reload.
  • A profile that has no timer yet shows "None scheduled" when selected, until the next reload or edit. Before, selecting it armed it by accident if its unit, count or time differed from the previous profile's.
  • A stored interval unit that the combo box does not know no longer raises IntegrityError inside the slot on populate, and an out-of-range count is no longer clamped and written back on populate.
  • Unchanged: selecting or unlinking a repository does not re-arm the timer (Stop re-arming failed scheduled runs early and drop timers on repo unset #2603). The validation, compaction, prune and catch-up widgets on the page still save when populated; each writes only its own field with the new profile's value.

How Has This Been Tested?

New tests in tests/unit/test_schedule.py:

  • test_profile_switch_interval_does_not_save_or_catch_up and test_profile_switch_fixed_does_not_save_or_catch_up select profile A, then B, through the profile selector. They assert that B's timer is not re-armed, B is not saved, B's row is unchanged, no backup is started, and the widgets show B's values. They end with one real edit, which must save B once and re-arm it once from B's own values; this shows that the hooks the test relies on are live and that signals are unblocked again. Without the change to schedule_page.py both fail: the interval case arms B from ('interval', 'hours', 1, …) and starts one catch-up, the fixed case arms three times and starts two.
  • test_import_over_current_profile_rearms_its_timer drives the real import dialog. It fails when only the line in main_window.py is removed: the next run stays on the old schedule.
  • test_schedule_edits_after_populate_still_save and test_repo_change_refreshes_next_backup_label_without_rearming are guards; they pass without the change.
  • Each of the three setters in populate_from_profile was deleted in turn, and each of the three signal blockers removed or left blocking in turn; the tests failed every time. test_missed_startup still guards on_scheduler_change callback causes race conditions in updating BackupProfile, causing spurious catch-up runs #2316: it passes with this change, and two of its cases fail when both the flag and the blockers are removed.

Runs, on macOS with Python 3.12 and PyQt 6.12:

  • tests/unit/test_schedule.py: 9 passed, repeatedly, in file order, reversed, and each new test on its own.
  • tests/unit without test_keyring_darwin.py: 369 passed, 7 skipped (364 on master without the five new tests).
  • The same with pytest-qt's event processing between test phases switched on, as it is on Linux: 369 passed, 7 skipped.
  • Merged with Always finish a Borg job and unblock the UI when it raises #2618: 388 passed, 7 skipped. No open pull request touches the three changed files.
  • ruff check and format pass on the changed files, also with the ruff version pinned in pre-commit.
  • Not tested: Linux itself, the nox matrix, the integration tests, and the application by hand.

Two notes on the test code:

  • The restore_default_profile fixture is there because the test set-up only calls deleteLater() on the previous test's main window, which stays connected to profile_changed_event. A test that ends on a profile the next test's database does not have makes that stale window raise in the event loop. Disconnecting profile_changed_event in tests/unit/conftest.py would remove the need for the fixture; it is left out here because other open pull requests change that file.
  • _wait_for_workers waits for the startup borg --version job. Always finish a Borg job and unblock the UI when it raises #2618 makes the shared fixtures do this, so whichever of the two is merged second can drop the helper.

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.

SchedulePage.populate_from_profile set the interval unit, interval
count and fixed time with signals enabled. On a profile switch, delete
or rename, each setter that changed a value ran on_scheduler_change
while the other widgets still held the previous profile's values. That
saved the mix to the newly selected profile and re-armed its timer from
it, and when the mixed schedule put the next run in the past, a
catch-up backup started.

Block the signals of the three widgets while they are populated. The
radio buttons stay unblocked because their toggled signal drives the
frames. The hasPopulatedScheduleFields flag from #2317 only covered the
first populate and is no longer needed.

Importing over the selected profile used to re-arm its timer through
that same side effect, so arm the imported profile explicitly, before
the confirmation dialog.

Fixes #2611
@m3nu
m3nu merged commit 07d9c92 into master Nov 15, 2026
8 of 10 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.

Switching profiles saves mixed schedule and can start a backup

1 participant