Recreate an empty DataStore table when a load fails - #29
Merged
jguo144 merged 2 commits intoJul 10, 2026
Conversation
When a Data Dictionary type override cannot be satisfied by the data (e.g. an integer column set to timestamp), the next xloader upload fails. Both the direct COPY and tabulator paths delete the existing table when field types change, and the tabulator reload runs create_table + insert in a single transaction; the failing insert rolls the whole thing back, leaving no table at all. Since type overrides live only in the DataStore table's column comments, the table, its data dictionary, and datastore_active are all gone -- the Data Dictionary tab disappears and the only recovery is a full re-upload. This captures the existing field definitions (types + data dictionary, including type overrides) before the load, and if all load attempts fail and the table was dropped, recreates an empty table with those fields so the Data Dictionary stays visible and editable. The user can then fix the column type and re-upload. Recovery is best-effort (its own errors are logged, never masking the real load error), skipped when the table still exists (a partial/ truncated load), skipped for brand-new resources with nothing to preserve, and gated behind the new ckanext.xloader.recreate_empty_table_on_error config option (default True). It deliberately does not persist the file hash or mark the table as containing all records, so re-uploading the corrected file still triggers a load. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
Capture the set_resource_metadata mock inside the patch context instead of reading jobs.set_resource_metadata after the context exits (which returned the real, restored function). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
nolanpruett
approved these changes
Jul 9, 2026
jguo144
deleted the
jguo144/recreate-empty-datastore-table-on-load-failure
branch
July 10, 2026 14:37
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.
Problem
When a user sets a Data Dictionary type override that the data can't satisfy (e.g. a
Vendor #column of integers set totimestamp), the next xloader upload fails and leaves the resource in a dead end:COPYfirst; on a bad value it fails, then falls back to tabulator.create_table+insertin a single transaction; the insert fails → the whole transaction rolls back → no table exists.datastore_activeare all gone — the Data Dictionary tab disappears and the user has no in-UI way to fix the type. Only a full re-upload recovers it.Fix
Capture the existing field definitions (types + data dictionary, including type overrides) before the load. If all load attempts fail and the table was dropped, recreate an empty table with those fields so the Data Dictionary stays visible and editable. The user then corrects the column type and re-uploads.
Key properties:
try/exceptand never masks the real load error, which is still re-raised (job status stayserror, log shows the true cause).ckanext.xloader.recreate_empty_table_on_erroroption (defaultTrue) lets operators disable it.Outcome
A failed upload leaves the resource recoverable — empty table,
datastore_activeTrue, Data Dictionary tab visible, original overrides intact — instead of a dead end.Tests
Added
TestRecreateEmptyTableOnErrorintest_jobs.py— unit tests that drivexloader_data_into_datastore_with collaborators mocked (no DB/RQ worker), covering: recreate-on-drop (fields/overrides preserved, hash not persisted), no-op when table survives, no-op for new resources, config-disabled, and recovery-never-masks-original-error.🤖 Generated with Claude Code