Fix delete not finding the download: wrong id sent to MeTube's /delete

MeTube's queue/pending/done stores are keyed by the download's URL
(PersistentQueue.put: key = value.info.url), not by the id field a Download
reports over Socket.IO (which is what we stored as metube_job_id and were
sending). Sending the wrong key made MeTube's clear()/cancel() silently
no-op ("requested delete for non-existent download" in its own logs) while
still returning {"status": "ok"} regardless -- confirmed live by curling
/history on the real instance and finding the "deleted" entry still
present, unrelated to the DELETE_FILE_ON_TRASHCAN config fix that came
right before this.

delete_download() now takes the video's canonical youtube_url instead.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-09-16 20:14:43 +00:00
parent 441a3ef9df
commit 62f8fb746b
3 changed files with 19 additions and 11 deletions

View file

@ -182,7 +182,7 @@ def test_delete_download_success(client, db_session, monkeypatch):
calls = {}
monkeypatch.setattr(
"app.services.metube_client.MeTubeClient.delete_download",
lambda self, metube_job_id: calls.setdefault("id", metube_job_id) or {"status": "ok"},
lambda self, youtube_url: calls.setdefault("youtube_url", youtube_url) or {"status": "ok"},
)
monkeypatch.setattr("app.services.metube_client.MeTubeClient.check_media", lambda self, url: False)
@ -191,7 +191,10 @@ def test_delete_download_success(client, db_session, monkeypatch):
assert resp.status_code == 200
assert resp.json()["status"] == "deleted"
assert resp.json()["media_url"] is None
assert calls["id"] == "vid1.vid1"
# MeTube's queue/done stores are keyed by URL, not by the id it reports
# over Socket.IO -- passing the wrong one is exactly the bug this
# regression test guards against (it silently no-ops on MeTube's side).
assert calls["youtube_url"] == video.youtube_url
db_session.refresh(job)
assert job.status == "deleted"
@ -214,7 +217,7 @@ def test_delete_download_file_still_present_returns_409(client, db_session, monk
db_session.commit()
monkeypatch.setattr(
"app.services.metube_client.MeTubeClient.delete_download", lambda self, metube_job_id: {"status": "ok"}
"app.services.metube_client.MeTubeClient.delete_download", lambda self, youtube_url: {"status": "ok"}
)
monkeypatch.setattr("app.services.metube_client.MeTubeClient.check_media", lambda self, url: True)