Skip to content

fix(sqllab): redirect legacy /superset/sql/<db_id>/ deep links - #41759

Merged
rusackas merged 1 commit into
apache:masterfrom
sadpandajoe:fix/sqllab-legacy-sql-deeplink-redirect
Jul 10, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
sadpandajoe:fix/sqllab-legacy-sql-deeplink-redirect

Conversation

@sadpandajoe

Copy link
Copy Markdown
Member

SUMMARY

When the /superset URL prefix was removed (Superset.route_base = ""), a closed-set 308 redirect shim (superset/middleware/legacy_prefix_redirect.py) was added to keep the enumerated bookmarkable /superset/* routes working for one release cycle. One route was intentionally excluded: /superset/sql/<database_id>/, because Database.sql_url changed shape from a path to a query string (/sqllab/?dbid=<id>), so there is no 1:1 path→path mapping for the closed-set map.

The side effect is that existing SQL Lab bookmarks / deep links of the form /superset/sql/5/ hard-404 instead of degrading gracefully like every other legacy /superset/* route. This PR closes that gap without weakening the closed-set discipline that protects the rest of the map.

Approach — a dedicated special case (_LEGACY_SQL_RE = ^/sql/(\d+)/?$) handled ahead of the closed-set lookup:

  • A numeric <database_id> → 308 to /sqllab/?dbid=<id>.
  • Any inbound query string is merged with & (so location never ends up with ?…?…).
  • The redirect respects the deployment app-root prefix (subdirectory deploys).
  • Non-GET methods → 410 Gone (the old route was GET-only; a 308 would make the client retry-POST against /sqllab/ → 405).
  • A non-numeric tail does not match _LEGACY_SQL_RE and falls through to the closed-set map (→ 404), so closed-set discipline is preserved for everything that isn't this specific, well-defined transform.

This is a deliberate, documented departure from the original "leave it to hard-404" decision: the module docstring is updated to explain why this one route is handled by a special case rather than the map.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before: GET /superset/sql/5/ → 404.
After: GET /superset/sql/5/ → 308 → /sqllab/?dbid=5.

TESTING INSTRUCTIONS

pytest tests/unit_tests/middleware/test_legacy_prefix_redirect.py

Added regression cases cover: numeric id → 308 to /sqllab/?dbid=<id>; query-string &-merge; app-root prefix; non-GET → 410; non-numeric tail falling through to the closed-set map (404).

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot Bot added the sqllab Namespace | Anything related to the SQL Lab label Jul 4, 2026
@bito-code-review

bito-code-review Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6af31c

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 6dfea03..6dfea03
    • superset/middleware/legacy_prefix_redirect.py
    • tests/unit_tests/middleware/test_legacy_prefix_redirect.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review

Copy link
Copy Markdown
Contributor

The suggestion to add explicit type annotations for sql_match and query_string is valid, as these variables are introduced in the middleware and currently lack explicit type hints. You can resolve this by annotating them as follows:

        if sql_match := _LEGACY_SQL_RE.match(canonical_after_strip):
            if method != "GET":
                return _response_with_location(410, None)(environ, start_response)
            location: str = f"{self.app_root_prefix}/sqllab/?dbid={sql_match.group(1)}"
            query_string: str = environ.get("QUERY_STRING", "")
            if query_string:
                location = f"{location}&{query_string}"
            return _response_with_location(308, location)(environ, start_response)

Regarding other comments on this PR, there are no additional review comments available in the provided context to address.

superset/middleware/legacy_prefix_redirect.py

location: str = f"{self.app_root_prefix}/sqllab/?dbid={sql_match.group(1)}"
            query_string: str = environ.get("QUERY_STRING", "")
            if query_string:
                location = f"{location}&{query_string}"

@codecov

codecov Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.79%. Comparing base (53c3b1c) to head (271dc72).

Files with missing lines Patch % Lines
superset/middleware/legacy_prefix_redirect.py 22.22% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41759      +/-   ##
==========================================
- Coverage   64.79%   64.79%   -0.01%     
==========================================
  Files        2692     2692              
  Lines      149038   149047       +9     
  Branches    34398    34401       +3     
==========================================
+ Hits        96573    96575       +2     
- Misses      50696    50703       +7     
  Partials     1769     1769              
Flag Coverage Δ
hive 39.19% <22.22%> (-0.01%) ⬇️
mysql 57.85% <22.22%> (-0.01%) ⬇️
postgres 57.91% <22.22%> (-0.01%) ⬇️
presto 40.72% <22.22%> (-0.01%) ⬇️
python 59.32% <22.22%> (-0.01%) ⬇️
sqlite 57.49% <22.22%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

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.

@sadpandajoe sadpandajoe added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Jul 5, 2026
When the `/superset` URL prefix was removed, `/superset/sql/<database_id>/`
was intentionally left out of the closed-set legacy redirect map because
`Database.sql_url` changed shape from a path to a query string
(`/sqllab/?dbid=<id>`), so no 1:1 path mapping exists. The consequence is
that existing SQL Lab bookmarks and deep links hard-404 rather than
degrading gracefully like every other legacy `/superset/*` route.

Handle it with a dedicated special case (`_LEGACY_SQL_RE`) rather than the
closed-set map: a numeric `<database_id>` 308-redirects to
`/sqllab/?dbid=<id>` (merging any inbound query string with `&`, and
respecting the deployment app-root prefix); a GET-only guard emits 410 for
non-GET methods (a 308 would have the client retry-POST against `/sqllab/`
→ 405); a non-numeric tail does not match and falls through to the map
(→ 404), preserving closed-set discipline everywhere else.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sadpandajoe
sadpandajoe force-pushed the fix/sqllab-legacy-sql-deeplink-redirect branch from 6dfea03 to 271dc72 Compare July 7, 2026 14:12
@bito-code-review

bito-code-review Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4473f6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 271dc72..271dc72
    • superset/middleware/legacy_prefix_redirect.py
    • tests/unit_tests/middleware/test_legacy_prefix_redirect.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas
rusackas merged commit e2ba378 into apache:master Jul 10, 2026
59 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-if-green If approved and tests are green, please go ahead and merge it for me size/L sqllab Namespace | Anything related to the SQL Lab

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants