Repository navigation
FIX: fetch_nb_dependencies must not save HTTP error pages - #904
Sanjays2402 wants to merge 1 commit into
Conversation
fetch_nb_dependencies wrote whatever the server returned straight to disk and appended True to the status list, so a request for a missing remote file saved GitHub's HTML error page under the requested filename and reported it as fetched. The failure only surfaced later as a parse error in unrelated code. - call raise_for_status() and append False on any RequestException instead of writing the response body - add a default request timeout, overridable via the timeout keyword - stop rebinding the loop variable to the open file handle - accept a tuple of filenames via isinstance instead of type(..) == list Closes QuantEcon#870
|
Thanks @Sanjays2402, and apologies for the outcome — closing this one alongside #905, which fixed the same bug and has also been closed. Neither is being closed on quality grounds. We have decided to retire the module rather than repair it. Worth saying plainly: you and the author of #905 filed within twenty-one minutes of each other, so neither of you could have seen the other's work. That collision was nothing either of you could have avoided — #870 sitting open as a high-priority bug is what drew you both to the same thirty lines on the same morning. We are closing #870 as well, so that nobody else repeats the work. Thanks for the time you put in, and please do pick up another issue if you would like. |
…#953) * DEPR: deprecate fetch_nb_dependencies and demote requests Deprecates `quantecon.util.notebooks` in 0.12.0 for removal in v1.0, and moves `requests` out of the mandatory dependency set into a `notebooks` extra that is removed with the module. `requests` served exactly one call site in the package. The function has no remaining constituency: no usage across lecture-python.myst, lecture-python-advanced.myst, lecture-python-intro or lecture-python-programming.myst, and the callers that exist are dormant notebooks descending from two 2017-era demos. Its default remote, QuantEcon/QuantEcon.notebooks, was last pushed 2023-07-15. Data still needed moves to QuantEcon/data-lectures. Calling the function emits a DeprecationWarning attributed to the caller's frame. Where `requests` is absent the lazy import raises an ImportError naming the extra. The stale 2016 TODO block, which no longer described the code, is replaced by the deprecation directive. Adds `r.raise_for_status()` as harm reduction for the module's final release: #870 reported that a missing remote path saved GitHub's 404 HTML page under the requested filename and reported success. Verified against the reported reproducer, which now raises HTTPError and writes no file. The other three defects in #870 are left unfixed, the function being scheduled for removal. Part of #880. Supersedes #870, #904 and #905, all closed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * TEST: skip the notebooks tests without requests; set the deprecation version to 0.13.0 Addresses two Copilot comments: the module is skipped with importorskip where requests (now the notebooks extra) is not installed, and the teardown no longer fails when raise_for_status left no file behind. The deprecation version becomes 0.13.0, the next release, matching #979. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes #870
fetch_nb_dependencieswrote whatever the server returned straight to disk and appendedTrueto the status list, so requesting a file that does not exist remotely saved GitHub's HTML error page under the requested filename and reported it as fetched — surfacing later as a parse error in unrelated code.This calls
raise_for_status()and appendsFalseon anyRequestExceptioninstead of writing the body, adds a default requesttimeout(overridable by keyword), stops rebinding the loop variable to the open file handle, and accepts a tuple viaisinstancerather thantype(files) == list.Three regression tests in
TestFetchNbDependenciesErrorscover the three behaviours; all three fail against the original source (error page written,timeoutrejected as an unexpected kwarg, tuple raisingAttributeError: 'tuple' object has no attribute 'keys') and pass with the fix. The two existing network tests are untouched.