wrolpi/wrolpi
lrnselfreliance 4fe58d8675
Fix Downloads stuck "pending": persist finalize_download mutations (#473)
* Persist finalize_download mutations; isolate child-download enqueue

A channel/RSS Download could get stuck permanently "pending".  Root cause:
the phase-split dispatch in signal_download_download passes the Download
loaded in an already-closed session to finalize_download, so it is
DETACHED.  ChannelDownloader.finalize_download sets
`download.sub_downloader = 'video'` (and info_json/collection_id) on that
detached object, so the write never reaches the DB.  The status block then
re-queries the Download fresh, reads sub_downloader=None, and calls
create_downloads(downloader_name=None) ->
`InvalidDownload: Cannot find downloader with name None`.

That exception was raised inside the status-commit transaction (outside the
inner try), so it (a) rolled back the parent's complete(), reverting it to
the `pending` set by started(), and (b) was swallowed by the outer bare
`except Exception`, which only logs.  Result: the parent never failed, never
completed — it sat `pending` forever, re-crashing the same way on every
restart.

Fixes:
- finalize_download is now given a Download re-loaded in (attached to) its
  own session, so its mutations persist.
- Child-download creation moves to its own transaction after the parent's
  status is committed.  A failure there is logged and cannot roll back or
  strand the parent.

The existing test harness reuses one shared DB session for every
get_db_session call, so detached-object and rollback bugs never reproduced
under it (which is why this shipped).  Add `production_like_sessions` to
conftest.py — a context manager handing out a fresh Session per call, like
production — and two regression tests that fail without the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Re-attach Download in prepare_download too (consistency)

prepare_download receives the same detached Download as finalize_download
did, so VideoDownloader.prepare_download's writes to the row
(destination/tag_names) are not reliably persisted.  Re-load the Download
attached to the prepare session, mirroring the finalize fix, so the row's
metadata is accurate.

Unlike sub_downloader (which the status block re-reads and feeds to
create_downloads), nothing downstream re-reads these values, so this is a
consistency/cosmetic improvement, not a functional bug — and it cannot be
made to fail in a test (the loaded Download's session outlives the worker),
so no dedicated test is added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Log (not swallow) session-close failures in production_like_sessions

Addresses Greptile review: surface a failed session.close() at debug level
instead of silently passing.  engine.dispose() still does the authoritative
cleanup, so the close failure remains non-fatal.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 17:22:22 -06:00
..
collections Creating browser extension to facilitate starting downloads. Chrome/Brave and Firefox supported. 2026-05-03 11:48:50 -06:00
files Handling aborted-transaction case when dropping fs_files work table. 2026-05-15 20:29:16 -06:00
scripts Map search added to global search. Preview cards are displayed for all results in new Map tab. 2026-04-13 12:17:08 -06:00
static/extensions Bump extension to v0.2.4 2026-06-01 19:23:39 -06:00
test Fix Downloads stuck "pending": persist finalize_download mutations (#473) 2026-06-04 17:22:22 -06:00
__init__.py Removing WROLPi admin functionality that is now in Controller. 2025-12-19 18:41:27 -07:00
api_utils.py Reworking how Sanic is run for upgraded Sanic version 2026-01-23 15:29:17 -07:00
captions.py Adding links next to video captions to allow scrubbing of video by the captions, adding filter to make finding quick. 2026-03-21 16:50:27 -06:00
cmd.py Key changes: 2026-04-04 13:48:19 -06:00
common.py Displaying warning when no drive is mounted. 2026-05-14 16:16:18 -06:00
config_api.py Fixing bug where configs could be overwritten with empty configs on first refresh. Fixing bug where configs were displayed as JSON in admin settings. 2026-03-22 12:56:37 -06:00
config_schema.py Backup configs can be restored in the UI. User can choose between Merge or Overwrite, the UI displays a comparison. Configs are compared when user opens the restore modal, configs which won't cause changes are marked. 2026-03-10 20:30:46 -06:00
conftest.py Fix Downloads stuck "pending": persist finalize_download mutations (#473) 2026-06-04 17:22:22 -06:00
contexts.py Key changes: 2026-04-04 13:48:19 -06:00
dates.py Testing that downloads have absolute destinations. Handling 'undefined', 'null', etc, dates. 2025-03-21 17:14:53 -06:00
db.py Creating AutoAwaitTestClient for tests which automatically runs background tasks and expires db objects. 2026-01-05 18:26:49 -07:00
downloader.py Fix Downloads stuck "pending": persist finalize_download mutations (#473) 2026-06-04 17:22:22 -06:00
errors.py Showing preview of zip file contents, allowing user to download individual files without full extraction. 2026-03-15 12:58:40 -06:00
events.py Map search added to global search. Preview cards are displayed for all results in new Map tab. 2026-04-13 12:17:08 -06:00
flags.py Displaying warning when no drive is mounted. 2026-05-14 16:16:18 -06:00
lang.py Including Country/Region codes in caption file names. 2024-10-16 18:56:31 -06:00
log_levels.py Reworking and unifying log levels. 2025-12-16 19:20:04 -07:00
logging_extra.py Hiding empty log line messages because Sanic's access log logs empty lines. 2025-03-28 10:25:32 -06:00
media_path.py FileGroups in Collections can be reorganized in the Collection's directory. 2026-01-31 18:08:41 -07:00
roland@learningselfreliance.com.gpg Updating git signing gpg key. 2024-10-16 18:57:06 -06:00
root_api.py Displaying warning when no drive is mounted. 2026-05-14 16:16:18 -06:00
schema.py fix: coerce sleep_requests and numeric settings from string form values 2026-05-31 13:02:31 -06:00
scrape_downloader.py Migrating FileDownloader. 2026-05-07 15:54:53 -06:00
switches.py Add Docs module for searching and organizing PDFs and EPUBs 2026-03-20 14:17:06 -06:00
tags.py Add Docs module for searching and organizing PDFs and EPUBs 2026-03-20 14:17:06 -06:00
test_media_path.py Add Docs module for searching and organizing PDFs and EPUBs 2026-03-20 14:17:06 -06:00
upgrade.py Not checking for updates when WROL Mode is enabled. 2025-12-06 15:11:37 -07:00
vars.py Reworking and unifying log levels. 2025-12-16 19:20:04 -07:00
version.py Bumping version. Moving version to text file for easy reference in scripts. 2023-05-03 13:39:58 -06:00
version.txt Bump version to 0.23.2-beta 2026-06-02 13:43:28 -06:00