Skip to content

fix(sqllab): retry table metadata preview after OAuth2 redirect#42390

Draft
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:aminghadersohi/sqllab-oauth2-table-preview-retry
Draft

fix(sqllab): retry table metadata preview after OAuth2 redirect#42390
aminghadersohi wants to merge 1 commit into
apache:masterfrom
aminghadersohi:aminghadersohi/sqllab-oauth2-table-preview-retry

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Superset's per-user database OAuth2 flow signals uniformly via OAuth2RedirectError (403, error_type=OAUTH2_REDIRECT). SQL Lab's DB/schema/table selectors already handle this: they render the error via ErrorMessageWithStackTrace source="crud", and OAuth2RedirectMessage listens for the popup completion and retries by invalidating the relevant RTK Query tags.

The SQL Lab table column/metadata preview (shown when expanding a table in the left panel) did not. On error it rendered a plain <Alert type="warning"> built from a flattened error string, so an OAuth2-required response never showed the authorization link and never refetched after the user completed the OAuth2 dance elsewhere — it just sat as a dead warning banner.

This PR makes the preview consistent with the rest of SQL Lab:

  1. TablePreview/index.tsx — render metadata errors via ErrorMessageWithStackTrace error={...} source="crud", passing the structured SupersetError (error.errors[0]) that RTK Query already provides instead of flattening it to a string. This lets the registered OAuth2RedirectMessage component render the "provide authorization" link and listen for completion, exactly like DatabaseSelector/TableExploreTree.

  2. OAuth2RedirectMessage.tsx — the crud-source retry only invalidated Schemas, Catalogs, and Tables, but the table metadata queries (useTableMetadataQuery / useTableExtendedMetadataQuery) provide the TableMetadatas tag. Without invalidating it, the preview would never refetch after re-auth. Add TableMetadatas to the invalidated tags so the preview auto-refreshes once the OAuth2 dance completes.

BEFORE/AFTER

Before After
Table preview metadata error ❌ plain warning Alert, no auth link, no retry ✅ "Authorization needed" link, auto-refetches after OAuth2

TESTING INSTRUCTIONS

  1. Create a DB connection that uses per-user OAuth2 (e.g. Snowflake external OAuth).
  2. In SQL Lab, expand a table in the left panel to open the column/metadata preview — you should see the "Authorization needed" banner with a link.
  3. Click the link and complete the OAuth2 dance in the popup.
  4. Expected: the preview populates automatically (columns/metadata) without a manual refresh.

Unit tests added:

  • TablePreview.test.tsx — a metadata error with error_type=OAUTH2_REDIRECT renders the OAuth2 authorization link.
  • OAuth2RedirectMessage.test.tsx — the crud retry now also invalidates TableMetadatas.

ADDITIONAL INFORMATION

  • Changes UI

The SQL Lab table column/metadata preview rendered a plain warning Alert on
error, so an OAuth2 DB-auth 403 (error_type=OAUTH2_REDIRECT) showed a dead
banner with no authorization link and never refetched after the user completed
the OAuth2 dance elsewhere.

Render the metadata error via ErrorMessageWithStackTrace with source="crud",
passing the structured SupersetError through (error.errors[0]) so the registered
OAuth2RedirectMessage component shows the authorization link and listens for
completion, matching DatabaseSelector and TableExploreTree.

The crud-source retry in OAuth2RedirectMessage only invalidated Schemas,
Catalogs and Tables, so the table metadata queries (tagged TableMetadatas) were
never refetched after re-auth. Add TableMetadatas to the invalidated tags so the
preview auto-refreshes once the OAuth2 dance completes.
@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit bc931df
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a63871ca221c60008a772ea
😎 Deploy Preview https://deploy-preview-42390--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.06%. Comparing base (18f1dd3) to head (bc931df).
⚠️ Report is 304 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42390      +/-   ##
==========================================
+ Coverage   65.03%   65.06%   +0.02%     
==========================================
  Files        2744     2744              
  Lines      153627   153628       +1     
  Branches    35226    35226              
==========================================
+ Hits        99915    99953      +38     
+ Misses      51805    51768      -37     
  Partials     1907     1907              
Flag Coverage Δ
javascript 70.44% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant