Skip to content

Name dumps after the live CKAN resource - #34

Merged
Gutts-n merged 1 commit into
mainfrom
fix/dump-filename-fresh-resource
Oct 28, 2026
Merged

Gutts-n merged 1 commit into
mainfrom
fix/dump-filename-fresh-resource

Conversation

@Gutts-n

@Gutts-n Gutts-n commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Refs datopian/neso-nextgen-shared#7 (UAT: download filename keeps the old name after a file is replaced)

The problem, in plain words

When someone replaces an uploaded file, CKAN updates the file's address (url) to the new name. But the datastore does not ask CKAN for the address each time. It keeps a saved copy of CKAN's answer for up to an hour (AUTH_CACHE_TTL=3600), and it built the download name from that saved copy. So for up to an hour after a replace, downloads in ndjson, gzip, parquet and the other dump formats still got the old file name. If someone had downloaded right after the first upload, they kept getting the first name.

The fix

Before naming a download, the datastore now asks CKAN (resource_show) for the current resource. The saved copy is still used for the permission check, so nothing gets slower or less safe there. If CKAN cannot be reached, it falls back to the saved copy so a download never fails because of this.

What changed

  • datastore/infrastructure/ckan_client.py: new resource_show call.
  • datastore/api/context.py: new RequestContext.fresh_resource(), live resource with a fallback to the cached one.
  • datastore/api/endpoints/dump.py: dump, dump_sql, and the data dictionary and metadata downloads now name the file from the live resource.
  • tests/conftest.py, tests/test_datastore_dump.py: the fake CKAN can now report a stale resource, plus two new tests (stale cache after a replace gets the new name; CKAN failure falls back to the cached name).

Verified

  • Full suite: 566 passed. ruff check and ruff format clean.
  • The new stale-cache test fails on main and passes with this change.
  • Reproduced the bug on dev first: CKAN url was sellorder-validate-c.csv, but the ndjson dump was still named personal.json.

Not verified / leftovers

  • Not run against the live dev service yet (needs a deploy).
  • The data dictionary and metadata downloads now also use the live resource only for naming. Their content still comes from the same code as before.
  • One extra CKAN call per download request. Not measured.
  • Resource uploaded as CSV and downloaded with the CSV button links straight to CKAN, unchanged.

Deployment

Merging does not deploy anything by itself. CI only runs tests. dx-helm-neso builds the datastore image from a pinned DATASTORE_REF in datastore/Dockerfile (currently 34a7370), so after merge that ref has to be bumped in dx-helm-neso and released to dev.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32bc4030-8189-4eed-9214-09e453ddefbc
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Gutts-n
Gutts-n merged commit 5b21ff4 into main Oct 28, 2026
2 checks passed
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.

1 participant