Repository navigation
fix(datasets): needs from one source are kept with one fetch - #239
Merged
Merged
Conversation
download_datasets() kept each need with download_need_figures(), which forgets the need figures held in memory before fetching. So a source with two needs, such as ONS's crime tables or UKHSA's vaccinations, was fetched twice in one run, and ONS rate-limits repeated requests. download_datasets() now forgets the need figures once, before it fetches, and keeps each need through what was fetched in the run. Calling download_need_figures() on its own still fetches afresh. Signed-off-by: billlyzhaoyh <billlyzhaoyh@users.noreply.github.com> Github-Issue: #238
billlyzhaoyh
force-pushed
the
fix/download-once-per-source
branch
from
December 4, 2026 17:39
15ddb0f to
2164bfa
Compare
The Codex review of #239 found three ways the fix changed what main did: - download_datasets() forgot the need figures held in memory even when no need was kept, such as when keeping the postcode table alone. It now forgets them only when a need is among the datasets kept. - A need's download in Dataset.downloads, run on its own, kept whatever was in memory and noted it as fetched today. It fetches afresh again, as on main. Only a run of download_datasets() shares what was fetched. - download_need_figures() forgot the figures before it refused an unknown need. It checks the need first, as on main. Each has a test that failed before the change. Github-Issue: #238
From the /simplify review of #239: - The two new vaccination tests served UKHSA a second time to see what was asked. The gov_uk fixture now hands out the fake request it already makes, as the homelessness and fuel poverty tests do. - _NeedDownload's docstring repeated how a run shares a fetch, which _run_with_others already says. No behaviour changes. Github-Issue: #238
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.
Closes #238.
The problem
download_datasets()kept each need withdownload_need_figures(need), which forgets the need figures held in memory before it fetches. Several needs share one source: homelessness, low income, vaccinations and crime each have two. So each of those sources was fetched twice in one run. ONS limits repeated requests, and during #237's review about 10 requests in a couple of minutes were refused. The workspace build will keep everything with onedownload_datasets()call in the 0.4.0 pin bump.The fix
download_datasets()now forgets the need figures once, before it fetches anything. It keeps each need through a newkeep_fetched_need_figures(need), which uses what is already held, so needs from one file share one fetch.download_need_figures()on its own still forgets first and fetches fresh figures, as before.Checks run
test_keeping_both_needs_fetches_ukhsa_once. It failed on main, where the three requests were made twice, and passes with the fix.ruff check,ruff format --check,ty check src, ast-grep as CI runs it, the fullpytest(1,294 passed),mkdocs build --strict.ons-police-recorded-crimeandukhsa-childhood-vaccinationsinto an empty folder made 6 requests, none repeated (12 before)./code-review(no bugs, four nits) and/simplify. From those, the new function gives a clear error for an unknown need and has a full docstring, and clearing was narrowed from every cache to the need figures.Not done: the census unemployment needs could share one Nomis query split by sex. That would be a separate change.
AI tools: Claude Code wrote the change and ran the checks above.