Fixing bug where editing video download could not save with collection_id.

This commit is contained in:
Roland 2026-02-23 15:24:41 -07:00
parent 50ead953d8
commit f4b293b0a0
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 50 additions and 0 deletions

View file

@ -218,7 +218,10 @@ class EchoResponse:
class DownloadSettings:
channel_id: Optional[int] = None
channel_tag_name: List[str] = field(default_factory=list)
channel_url: Optional[str] = None
collection_id: Optional[int] = None
depth: Optional[int] = None
destination: Optional[str] = None # Legacy support
download_metadata_only: bool = False
download_order: Optional[str] = None
excluded_urls: Optional[str] = None
@ -226,6 +229,7 @@ class DownloadSettings:
maximum_duration: Optional[int] = None
minimum_duration: Optional[int] = None
suffix: Optional[str] = None
tag_names: Optional[List[str]] = None # Legacy support
title_exclude: Optional[str] = None
title_include: Optional[str] = None
video_count_limit: Optional[int] = None

View file

@ -428,6 +428,52 @@ async def test_download_crud(test_session, async_client, test_download_manager_c
assert download_config['tag_names'] == [tag1.name, tag2.name]
@pytest.mark.asyncio
async def test_update_download_with_settings_collection_id(test_session, async_client, test_download_manager_config,
test_directory):
"""Updating a download should accept collection_id and other legacy fields in settings.
The frontend sends collection_id inside settings when editing a download, even though it's also at the top level.
This should not cause a validation error."""
async def dispatch_downloads(*a, **kw):
pass
with mock.patch('wrolpi.downloader.DownloadManager.dispatch_downloads', dispatch_downloads):
# Create a recurring download first.
body = dict(
urls=['https://www.youtube.com/watch?v=r9pF8CdUbD0'],
frequency=86400,
downloader='video',
)
request, response = await async_client.post('/api/download', content=json.dumps(body))
assert response.status_code == HTTPStatus.CREATED
download = test_session.query(Download).one()
# Update the download with collection_id in settings (mimics frontend behavior).
# This is the exact payload from the bug report.
body = dict(
destination='',
downloader='video',
settings=dict(
video_format='mp4',
video_resolutions=['360p'],
collection_id=195, # This was causing ValidationError
parent_download_url='https://youtube.com/@cheimerdinger/videos',
channel_tag_name=None,
channel_url='https://youtube.com/@cheimerdinger', # Also stored in settings
destination='videos/test', # Legacy field
tag_names=['test'], # Legacy field
),
tag_names=[],
urls=['https://www.youtube.com/watch?v=r9pF8CdUbD0'],
)
request, response = await async_client.put(f'/api/download/{download.id}', json=body)
assert response.status_code == HTTPStatus.NO_CONTENT, \
f'Expected NO_CONTENT but got {response.status_code}: {response.json}'
@pytest.mark.asyncio
async def test_get_downloaders(async_client):
"""A list of Downloaders the user can use can be gotten."""