fix(import): skip redundant has_table check when dataset import has no data URI - #43808
fix(import): skip redundant has_table check when dataset import has no data URI#43808Kunal8954 wants to merge 2 commits into
Conversation
…o data URI Database.has_table() opens a live connection and runs a schema- introspection query against the target database. Its result was only ever consulted to decide whether to call load_data(), which itself is already a no-op when a dataset's config has no 'data' URI. For bulk imports of dataset metadata (the common case, with no inline data), this meant one unconditional, unnecessary round trip to the target database per dataset — a major contributor to large imports (e.g. 293 datasets) timing out on the gunicorn worker. Only call has_table() when a data URI is actually present. Closes: apache#43764
Code Review Agent Run #0b7c1bActionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43808 +/- ##
==========================================
+ Coverage 79.35% 79.46% +0.11%
==========================================
Files 2893 2896 +3
Lines 167502 168275 +773
Branches 38801 38925 +124
==========================================
+ Hits 132920 133719 +799
+ Misses 32086 32055 -31
- Partials 2496 2501 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| import_dataset(config) | ||
|
|
||
| has_table.assert_called_once() |
There was a problem hiding this comment.
If has_table() returns False, this import should still load the supplied data, but this test returns True and never reaches load_data. An inverted/reindented condition would therefore pass the new coverage while skipping initialization of a missing table. Could this patch load_data and assert one call for the absent-table case?
There was a problem hiding this comment.
Good point, the has_table=True case never reached load_data so it proved
very little. Patched load_data in both tests now: not called when the table
exists, called once when it doesn't. Checked it catches the inverted
condition you described — flipping not table_exists fails both new
assertions.
|
The current implementation correctly optimizes the import process by wrapping the To address the case where tests/unit_tests/datasets/commands/importers/v1/import_test.py |
Patch load_data in both data-URI tests and assert on it: not called when has_table reports the table already exists, called once when it doesn't. Without this, an inverted or misindented condition would skip loading a missing table while still satisfying the has_table assertion. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015kAvbZ6SeKgp6jbGcvpXSh
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #855b14Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Summary
Fixes #43764 — bulk dataset imports (e.g. 293 datasets) time out on the gunicorn worker.
Root cause
For every dataset being imported,
Database.has_table()was called unconditionally. This opens a live connection to the target database and runs a schema-introspection query — a real network round trip. Its result was only ever used to decide whether to callload_data(), which is itself a no-op unless the dataset's config carries an inlinedataURI (uncommon — most bulk metadata imports don't). So for a typical bulk import of dataset definitions, every single dataset paid for one wasted database round trip.Fix
Only call
has_table()whendata_uriis actually present, since that's the only case where its result is ever used.Testing
Added two unit tests: one asserting
has_tableis not called when there's no data URI, one asserting it is called when there is one.