A recurring Download with more than one URL is an error (#887)

POST /api/download created a recurring Download from the first URL and silently dropped the rest, while answering
201.  No client sends more than one URL with a frequency (each recurring form has one URL field), so reject it, as
PUT /api/download/<id> already does.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-10-27 15:57:41 -06:00 • committed by Roland
parent 22ada7eb57
commit b14a32c7bc
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 17 additions and 0 deletions

View file

@ -383,6 +383,9 @@ async def post_download(request: Request, body: schema.DownloadRequest):
# Raises an InvalidDownload if the Downloader cannot be found.
download_manager.find_downloader_by_name(body.downloader)
if body.frequency and len(body.urls) != 1:
raise ValidationError('Only one URL can be specified for a recurring Download')
kwargs = dict(downloader_name=body.downloader,
sub_downloader_name=body.sub_downloader, reset_attempts=True,
destination=body.destination, tag_names=body.tag_names,

View file

@ -975,6 +975,20 @@ async def test_process_runner_output(async_client, test_directory, test_download
assert result.stderr == b'bad standard error\n'
@pytest.mark.asyncio
async def test_recurring_download_one_url(async_client, test_session, test_download_manager, test_downloader):
"""A recurring Download has one URL; more are an error, not silently dropped."""
body = dict(
urls=['https://example.com/1', 'https://example.com/2'],
downloader=test_downloader.name,
frequency=DownloadFrequency.weekly,
)
request, response = await async_client.post('/api/download', content=json.dumps(body))
assert response.status_code == HTTPStatus.BAD_REQUEST, response.body
assert 'one URL' in response.json['error']
assert test_session.query(Download).count() == 0
@pytest.mark.asyncio
async def test_crud_download(async_client, test_session, test_download_manager, test_downloader):
"""Test the ways that Downloads can be created."""