-
Notifications
You must be signed in to change notification settings - Fork 14.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sqllab): correct URL format for SQL Lab permalinks #32154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-review
on 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-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command 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 ReportAttention: 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the pr and separated permalink_view from root and works well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for hotfix
(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
sqllab
role and access to the dataset).ADDITIONAL INFORMATION