Skip to content

FIX: fetch_nb_dependencies must not save HTTP error pages - #904

Closed
Sanjays2402 wants to merge 1 commit into
QuantEcon:mainfrom
Sanjays2402:fix/fetch-nb-dependencies-http-errors
Closed

Sanjays2402 wants to merge 1 commit into
QuantEcon:mainfrom
Sanjays2402:fix/fetch-nb-dependencies-http-errors

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #870

fetch_nb_dependencies wrote whatever the server returned straight to disk and appended True to 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 appends False on any RequestException instead of writing the body, adds a default request timeout (overridable by keyword), stops rebinding the loop variable to the open file handle, and accepts a tuple via isinstance rather than type(files) == list.

Three regression tests in TestFetchNbDependenciesErrors cover the three behaviours; all three fail against the original source (error page written, timeout rejected as an unexpected kwarg, tuple raising AttributeError: 'tuple' object has no attribute 'keys') and pass with the fix. The two existing network tests are untouched.

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
@mmcky

mmcky commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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. quantecon/util/notebooks.py will be deprecated in 0.12.0 and removed in v1.0. requests is a hard dependency of QuantEcon.py solely to serve fetch_nb_dependencies, and the function has no remaining constituency — no usage in any of the lecture repositories, and the few callers we can find are dormant notebooks descending from two 2017-era demos. Its default remote was last updated in 2023. Any data still needed will move to QuantEcon/data-lectures, the canonical home for datasets referenced by stable URLs.

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.

@mmcky mmcky closed this Sep 9, 2026
mmcky added a commit that referenced this pull request Oct 8, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FIX: fetch_nb_dependencies writes HTTP error pages to disk and reports success

2 participants