fix(sqllab): correct URL format for SQL Lab permalinks#32154
fix(sqllab): correct URL format for SQL Lab permalinks#32154geido merged 16 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Fix Detected |
|---|---|---|
| Unsafe URL Pattern Replacement ▹ view | ✅ | |
| Incorrect API Documentation ▹ view | ✅ |
Files scanned
| File Path | Reviewed |
|---|---|
| superset-frontend/src/dashboard/components/nativeFilters/state.ts | ✅ |
| superset/sqllab/permalink/api.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-reviewon this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-reviewcommand in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-descriptioncommand in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolvecommand in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #32154 +/- ##
===========================================
+ Coverage 60.48% 83.46% +22.98%
===========================================
Files 1931 545 -1386
Lines 76236 39047 -37189
Branches 8568 0 -8568
===========================================
- Hits 46114 32592 -13522
+ Misses 28017 6455 -21562
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
betodealmeida
left a comment
There was a problem hiding this comment.
Thanks for fixing this! I suggested a more robust solution.
superset/sqllab/permalink/api.py
Outdated
| url = url_for("SqllabView.root", key=key, _external=True) | ||
| if "/sqllab/?key=" in url: | ||
| url = url.replace("/sqllab/?key=", "/sqllab/p/") |
There was a problem hiding this comment.
Oops, my bad. Looking at the view:
@expose("/", methods=["GET", "POST"])
@expose("/p/<string:permalink>/", methods=["GET"])
@has_access
@permission_name("read")
@event_logger.log_this
def root(self, **kwargs: Any) -> FlaskResponse:
payload = {}
if form_data := request.form.get("form_data"):
with contextlib.suppress(json.JSONDecodeError):
payload["requested_query"] = json.loads(form_data)
return self.render_app_template(payload)Looks like this is what we want:
| url = url_for("SqllabView.root", key=key, _external=True) | |
| if "/sqllab/?key=" in url: | |
| url = url.replace("/sqllab/?key=", "/sqllab/p/") | |
| url = url_for("SqllabView.root", permalink=key, _external=True) |
In general, we should always build internal URLs using url_for.
There was a problem hiding this comment.
So after testing this locally it still will not work.It displays the same query despite copying different queries.
There was a problem hiding this comment.
Can you try this:
@expose("/", methods=["GET", "POST"], endpoint="root") # <= here
@expose("/p/<string:permalink>/", methods=["GET"], endpoint="root_p") # <= here
@has_access
@permission_name("read")
@event_logger.log_this
def root(self, **kwargs: Any) -> FlaskResponse:
payload = {}
if form_data := request.form.get("form_data"):
with contextlib.suppress(json.JSONDecodeError):
payload["requested_query"] = json.loads(form_data)
return self.render_app_template(payload)And then do:
url = url_for("SqllabView.root_p", permalink=key, _external=True)There was a problem hiding this comment.
@expose("/", methods=["GET", "POST"], endpoint="root")
TypeError: expose() got an unexpected keyword argument 'endpoint' after adding the endpoint.
There was a problem hiding this comment.
Updated the pr and separated permalink_view from root and works well.
(cherry picked from commit f9f8c5d)
(cherry picked from commit 2770bc0)
fix(sqllab): correct URL format for SQL Lab permalinks
SUMMARY
This PR fixes an issue from this PR by ensuring that permalinks use the correct /sqllab/p/{key} format instead of ?key={key} while still using url_for. Previously , url_for("SqllabView.root", key=key, _external=True) generated URLs in the query parameter format (?key={key}), which caused issues when sharing permalinks across users.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
sqllabrole and access to the dataset).ADDITIONAL INFORMATION