Skip to content

Fix the metered networks checkbox so it saves and survives a restart - #2573

Open
theluckystrike wants to merge 1 commit into
borgbase:masterfrom
theluckystrike:fix/vorta-metered-checkbox
Open

theluckystrike wants to merge 1 commit into
borgbase:masterfrom
theluckystrike:fix/vorta-metered-checkbox

Conversation

@theluckystrike

Copy link
Copy Markdown

Description

The "Run backups over metered networks" checkbox on the Networks page doesn't store a change and shows the wrong state after a restart.

  • QCheckBox.stateChanged sends an int in PyQt6. on_metered_networks_state_changed compared it with the Qt.CheckState.Checked enum, which never matches, so every click stored dont_run_on_metered_networks = True.
  • The handler then reset the checkbox from a profile object loaded before the save, so the box flipped back.
  • populate_wifi never set the checkbox from the profile, so after a restart or profile switch it always showed unchecked.

The handler now converts the value with Qt.CheckState(state), the same way misc_tab.py and extract.py do, and drops the stale reset. populate_wifi sets the checkbox from the profile with signals blocked, so loading the page writes nothing. The .ui file, the model default and the migrations are unchanged.

Related Issue

Fixes #2557. The reporter traced the problem to networks_page.py and the stored value in backupprofilemodel, and both match what I found.

Motivation and Context

With the old code a user on a phone hotspot can't allow metered backups. Every scheduled run logs Backup skipped: Not running backup over metered connection. and the profile keeps dont_run_on_metered_networks = 1 whatever the checkbox shows.

How Has This Been Tested?

New tests/unit/test_networks_page.py has 2 tests. The first loads the window with metered backups allowed and expects a ticked box. The second clicks the box twice and reads the stored profile value after each click, so both directions are covered.

I ran everything on macOS 26.6, Python 3.12.13, PyQt6 6.10.1, borgbackup 1.4.4, with QT_QPA_PLATFORM=offscreen. Offscreen Qt on macOS leaves NSApp unset, so pytest ran through a small wrapper that calls NSApplication.sharedApplication() first.

$ pytest tests/unit/test_networks_page.py -q        # master c14a801 plus the new test file
FAILED tests/unit/test_networks_page.py::test_metered_checkbox_reflects_profile_on_load
FAILED tests/unit/test_networks_page.py::test_metered_checkbox_click_persists
2 failed in 13.64s

$ pytest tests/unit/test_networks_page.py -q        # this branch
2 passed in 1.34s

$ pytest --cov=vorta tests/unit                     # this branch
306 passed, 7 skipped, 6 warnings in 101.81s (0:01:41)

$ pre-commit run --all-files --show-diff-on-failure
ruff.....................................................................Passed
ruff-format..............................................................Passed
(all hooks Passed)

$ mypy src/vorta/store/ src/vorta/network_status/
Success: no issues found in 9 source files

End to end I started Vorta through vorta.__main__.main() with --development <dir>, opened Schedule > Networks, clicked the checkbox indicator with QTest.mouseClick, quit, and read backupprofilemodel.dont_run_on_metered_networks with sqlite3 after each separate process start.

master c14a801     box on start   box at quit   db
start              False          False         1
start, click       False          False         1
restart            False          False         1

this branch        box on start   box at quit   db
start              False          False         1
start, click       False          True          0
restart            True           True          0
restart, click     True           False         1
restart            False          False         1

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.
  • 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.

Ticking "Run backups over metered networks" on Schedule > Networks never
reached the database, so dont_run_on_metered_networks stayed 1 and
create.py skipped every backup on a metered connection (issue borgbase#2557).

QCheckBox.stateChanged passes a plain int in PyQt6, and an int never
equals the Qt.CheckState enum, so every click stored True. The handler
then reset the box from a profile fetched before the save, which flipped
it back. populate_wifi never set the box at all, so after a restart or a
profile switch it showed unchecked whatever the database held.

I convert the state with Qt.CheckState(state) as misc_tab.py and
extract.py already do, drop the stale setChecked call, and set the box
from the profile in populate_wifi with signals blocked so loading writes
nothing. The .ui file, the model default and migrations are unchanged.
tests/unit/test_networks_page.py covers the value shown on load and
clicks persisting in both directions.

I ran the following on macOS 26.6 with Python 3.12.13, PyQt6 6.10.1,
borgbackup 1.4.4 and QT_QPA_PLATFORM=offscreen. Offscreen Qt on macOS
leaves NSApp unset, so pytest ran through a small wrapper that calls
NSApplication.sharedApplication() first.

Master c14a801 with the new test file

    $ pytest tests/unit/test_networks_page.py -q
    FAILED tests/unit/test_networks_page.py::test_metered_checkbox_reflects_profile_on_load
    FAILED tests/unit/test_networks_page.py::test_metered_checkbox_click_persists
    2 failed in 13.64s

This commit

    $ pytest tests/unit/test_networks_page.py -q
    2 passed in 1.34s

    $ pytest --cov=vorta tests/unit
    306 passed, 7 skipped, 6 warnings in 101.81s (0:01:41)

    $ pre-commit run --all-files --show-diff-on-failure
    ruff.....................................................................Passed
    ruff-format..............................................................Passed

    $ mypy src/vorta/store/ src/vorta/network_status/
    Success: no issues found in 9 source files

End to end I started Vorta through vorta.__main__.main() in development
mode on a fresh config dir, opened Schedule > Networks, clicked the checkbox
indicator with QTest.mouseClick, quit, and read
backupprofilemodel.dont_run_on_metered_networks with sqlite3 after each
separate process start.

    master c14a801     box on start   box at quit   db
    start              False          False         1
    start, click       False          False         1
    restart            False          False         1

    this commit        box on start   box at quit   db
    start              False          False         1
    start, click       False          True          0
    restart            True           True          0
    restart, click     True           False         1
    restart            False          False         1

I didn't run make test-unit through nox (I ran the same pytest call in
a uv venv), the Linux xvfb job, the integration tests and a click in
a visible macOS window here.

Signed-off-by: Michael Lip <51033404+theluckystrike@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Backup over metered connection setting doesn't work and doesn't persist

1 participant