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 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-10-09 14:32:14 -06:00
parent 298988503e
commit aca2fed8e6
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 28 additions and 0 deletions

View file

@ -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

View file

@ -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."""