Repository navigation
Don't save or re-arm the schedule when a profile is loaded - #2620
Merged
Merged
Conversation
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
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
Loading a profile into the schedule page no longer saves anything or re-arms a timer.
SchedulePage.populate_from_profilesets the interval unit, interval count and fixed time insideQtCore.QSignalBlockercontext managers, soon_scheduler_changedoes 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: theirtoggledsignal enables and disables the two frames, andsetChecked()does not emitclicked, which is the signal that saves.hasPopulatedScheduleFieldsis removed. It was added in fix: Delay updating schedule until after fields have been initialized #2317 foron_scheduler_changecallback 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_eventnow callsscheduler.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.QSignalBlockeras a context manager is new in this codebase; the other sites useblockSignals(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_changeonce 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
schedule_changed. The "next backup" label is still redrawn from the scheduler's state.IntegrityErrorinside the slot on populate, and an out-of-range count is no longer clamped and written back on populate.How Has This Been Tested?
New tests in
tests/unit/test_schedule.py:test_profile_switch_interval_does_not_save_or_catch_upandtest_profile_switch_fixed_does_not_save_or_catch_upselect 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 toschedule_page.pyboth 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_timerdrives the real import dialog. It fails when only the line inmain_window.pyis removed: the next run stays on the old schedule.test_schedule_edits_after_populate_still_saveandtest_repo_change_refreshes_next_backup_label_without_rearmingare guards; they pass without the change.populate_from_profilewas deleted in turn, and each of the three signal blockers removed or left blocking in turn; the tests failed every time.test_missed_startupstill guardson_scheduler_changecallback 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/unitwithouttest_keyring_darwin.py: 369 passed, 7 skipped (364 on master without the five new tests).Two notes on the test code:
restore_default_profilefixture is there because the test set-up only callsdeleteLater()on the previous test's main window, which stays connected toprofile_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. Disconnectingprofile_changed_eventintests/unit/conftest.pywould remove the need for the fixture; it is left out here because other open pull requests change that file._wait_for_workerswaits for the startupborg --versionjob. 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
Checklist:
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.