Conversation
|
Thanks @earfman, and sorry to be closing this one — it is a thorough piece of work and the diagnosis went well beyond what the issue asked for. Two findings in particular were yours rather than ours: that We have decided to retire the module instead of repairing it. Given that, merging a fix to a function scheduled for removal would spend review on code we are deleting, so we are closing this and #904 together, and closing #870 as well so that nobody else picks it up and repeats the work. That last part is on us — #870 sat open as a high-priority bug and drew two independent fixes on the same morning. Thank you for the care you put into this, and please do consider another issue on the tracker if you would like — this one simply stopped being worth fixing. |
|
Thanks @mmcky, that makes sense. Retiring it beats patching something nobody calls. For transparency, this one was AI-assisted (Assisted-by: claude opus5), and I'll put that line on anything I send from here on. I'll look through the tracker for something else. |
Fixes #870
Addresses all six acceptance criteria from the issue.
Behaviour change
A failed request no longer produces a file. Previously the response body was written unconditionally and
Trueappended, so a missing remote path saved GitHub's HTML error page under the requested filename and reported it as fetched — the failure surfaced later as a parse error somewhere unrelated.Reproduced against a local server returning 404 (no network dependency):
While verifying I found one more consequence worth flagging: with
overwrite=True, the old code replaced a good local file with the error page and still reported success. A file containing real data became<html>...404...</html>. That is silent data loss, and it is also fixed here.Changes
raise_for_status()inside atry; onrequests.RequestExceptionthe code warns, appendsFalse, and skips the writeTIMEOUT = (10, 30)(connect, read), overridable via a newtimeout=keyword argumentas frather thanas fl)isinstance(files, (list, tuple))replacestype(files) == list, so a tuple no longer falls through to the dict branch and raisesAttributeErrorI looked at the
update-fetch-utilitybranch mentioned in the issue — it is docstring reformatting and import hoisting only, none of the four defects are addressed there, so nothing to salvage.Tests
New
TestFetchFailuresclass, offline (a localhttp.serveron an ephemeral port,tmp_path+monkeypatch.chdir, no network, no stray files): missing remote file returnsFalseand writes nothing, a 200 still writes correct bytes, tuple input is accepted, and the timeout is forwarded — including an assertion that the default is a real bound rather thanNone.The two existing tests are unchanged and still pass. Worth knowing: they fetch a live URL, so in a sandbox without access to github.com they were previously passing on a saved error page (the bug passing its own test). They pass normally against the real URL, which is what CI sees.
Notes for review
requestsexceptions propagating now getFalsein the status list instead. The new Returns section documents this; happy to re-raise instead if you would rather keep the exception contract.raise_for_status()only inspects the HTTP status. A host that returns 200 with an HTML page for a wrong path would still be written verbatim; a content-type check would be a separate change.(10, 30)default is a per-read-gap timeout, not a total budget: a slow-but-steady large download still succeeds. I checked that a 120 KB transfer trickling over ~58s completes fine.