From aca2fed8e6e81103972dd319607312e9e2b11b4d Mon Sep 17 00:00:00 2001 From: Roland Date: Fri, 9 Oct 2026 14:32:14 -0600 Subject: [PATCH] downloads: editing to "Once" stores a once-download, not frequency 0 Once-downloads have a NULL frequency. A 0 frequency counted as recurring (frequency != None) but could never be scheduled (not frequency), so an edited download stayed on the recurring list and could break renewal. Co-Authored-By: Claude Opus 5.5 --- wrolpi/downloader.py | 2 ++ wrolpi/test/test_root_api.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index 84727acd..9eae4baa 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -1062,6 +1062,8 @@ class DownloadManager: sub_downloader: str | None = None, frequency: int = None, settings: Dict = None, collection_id: int = None) -> Download: download = Download.find_by_id(session, id_) + # A once-download has no frequency; a frequency of 0 ("Once") is never stored as an interval. + frequency = frequency or None if collection_id and not frequency: raise InvalidDownload(f'A once-download cannot be associated with a Collection') download.url = url diff --git a/wrolpi/test/test_root_api.py b/wrolpi/test/test_root_api.py index a8163666..4b8eff7a 100644 --- a/wrolpi/test/test_root_api.py +++ b/wrolpi/test/test_root_api.py @@ -584,6 +584,32 @@ async def test_update_download_with_settings_collection_id(test_session, async_c f'Expected NO_CONTENT but got {response.status_code}: {response.json}' +@pytest.mark.asyncio +async def test_update_download_frequency_once(test_session, async_client, test_download_manager_config, + test_download_manager): + """Editing a recurring Download to a frequency of 0 ("Once") stores a once-download, not a zero interval.""" + + async def dispatch_downloads(*a, **kw): + pass + + with mock.patch('wrolpi.downloader.DownloadManager.dispatch_downloads', dispatch_downloads): + body = dict(urls=['https://example.com/feed.xml'], downloader='rss', sub_downloader='archive', + frequency=86400) + request, response = await async_client.post('/api/download', json=body) + assert response.status_code == HTTPStatus.CREATED + download = test_session.query(Download).one() + assert download.frequency == 86400 + + body = dict(urls=['https://example.com/feed.xml'], downloader='rss', sub_downloader='archive', frequency=0) + request, response = await async_client.put(f'/api/download/{download.id}', json=body) + assert response.status_code == HTTPStatus.NO_CONTENT, response.json + + test_session.expire_all() + download = test_session.query(Download).one() + assert download.frequency is None + assert test_download_manager.get_recurring_downloads(test_session) == [] + + @pytest.mark.asyncio async def test_get_downloaders(async_client): """A list of Downloaders the user can use can be gotten."""