FIX: do not write failed downloads to disk in fetch_nb_dependencies - #905
Open
earfman wants to merge 2 commits into
Open
FIX: do not write failed downloads to disk in fetch_nb_dependencies#905earfman wants to merge 2 commits into
earfman wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.