Repository navigation
fix(sqllab): redirect legacy /superset/sql/<db_id>/ deep links - #41759
Conversation
Code Review Agent Run #6af31cActionable 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 |
|
The suggestion to add explicit type annotations for 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 |
Codecov Report❌ Patch coverage is
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
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:
|
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]>
6dfea03 to
271dc72
Compare
Code Review Agent Run #4473f6Actionable 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
When the
/supersetURL 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>/, becauseDatabase.sql_urlchanged 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:<database_id>→ 308 to/sqllab/?dbid=<id>.&(solocationnever ends up with?…?…)./sqllab/→ 405)._LEGACY_SQL_REand 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
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