From e8b28d05e09ba7b62e6d865c1cbc731db64c062a Mon Sep 17 00:00:00 2001 From: splitsec2 <35583321+splitsec2@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:15:44 -0600 Subject: [PATCH] fix(sources): take the retry download URL from the release cache only (#1597) Newznab and Jackett fell back to the download URL sent with the queue request when the release was no longer in the cache. Prowlarr already returns no URL in that case, so this makes the other two match it: the retry URL comes from the cache and nothing else. A request for a release that has expired from the cache now fails with "Release not found in cache" instead of being queued with whatever URL came along. The new tests cover both handlers on a cache miss and with no source_id, and they fail on main. Full suite, ruff and basedpyright pass. --- shelfmark/release_sources/jackett/handler.py | 3 +- shelfmark/release_sources/newznab/handler.py | 8 ++--- tests/download/test_orchestrator_retry_url.py | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tests/download/test_orchestrator_retry_url.py diff --git a/shelfmark/release_sources/jackett/handler.py b/shelfmark/release_sources/jackett/handler.py index 943c0db1..12c72d25 100644 --- a/shelfmark/release_sources/jackett/handler.py +++ b/shelfmark/release_sources/jackett/handler.py @@ -86,7 +86,8 @@ class JackettHandler(ExternalClientHandler): source_id = normalize_optional_text(release_data.get("source_id")) result = get_release(source_id) if source_id else None if result is None: - return {} + # Never fall back to the URL the client sent along with the request. + return {"retry_download_url": None, "retry_download_protocol": None} protocol = get_protocol(result) return { diff --git a/shelfmark/release_sources/newznab/handler.py b/shelfmark/release_sources/newznab/handler.py index adae2609..9c386685 100644 --- a/shelfmark/release_sources/newznab/handler.py +++ b/shelfmark/release_sources/newznab/handler.py @@ -93,12 +93,10 @@ class NewznabHandler(ExternalClientHandler): def build_retry_resolution_fields(self, release_data: dict) -> dict: source_id = normalize_optional_text(release_data.get("source_id")) - if source_id is None: - return {} - - result = get_release(source_id) + result = get_release(source_id) if source_id else None if result is None: - return {} + # Never fall back to the URL the client sent along with the request. + return {"retry_download_url": None, "retry_download_protocol": None} protocol = _get_protocol(result) return { diff --git a/tests/download/test_orchestrator_retry_url.py b/tests/download/test_orchestrator_retry_url.py new file mode 100644 index 00000000..c0c6006c --- /dev/null +++ b/tests/download/test_orchestrator_retry_url.py @@ -0,0 +1,31 @@ +"""The retry URL comes from server data, never from the queue request.""" + +import pytest + +from shelfmark.download import orchestrator + + +@pytest.mark.parametrize("source", ["newznab", "jackett"]) +def test_cache_miss_drops_client_supplied_download_url(source): + fields = orchestrator._build_retry_resolution_fields( + { + "source": source, + "source_id": "not-in-the-cache", + "download_url": "http://169.254.169.254/latest/meta-data/", + "protocol": "torrent", + "title": "Some Book", + } + ) + + assert fields["retry_download_url"] is None + assert fields["retry_download_protocol"] is None + + +@pytest.mark.parametrize("source", ["newznab", "jackett"]) +def test_missing_source_id_drops_client_supplied_download_url(source): + fields = orchestrator._build_retry_resolution_fields( + {"source": source, "download_url": "http://10.0.0.1/x", "protocol": "usenet"} + ) + + assert fields["retry_download_url"] is None + assert fields["retry_download_protocol"] is None