-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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(explore): strip semicolons in virtual table SQL #13801
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13801 +/- ##
==========================================
- Coverage 78.35% 78.20% -0.15%
==========================================
Files 934 934
Lines 47349 47348 -1
Branches 5941 5943 +2
==========================================
- Hits 37101 37030 -71
- Misses 10104 10174 +70
Partials 144 144
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
one code quality comment
I don't think you need a new method just for this. The fix should be as simple as this diff: diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 2b61520cd..ea874167b 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -833,6 +833,8 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
"""
Render sql with template engine (Jinja).
"""
+ if not self.sql:
+ return ""
sql = self.sql
if template_processor:
try:
@@ -844,7 +846,7 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
msg=ex.message,
)
)
- sql = sqlparse.format(sql, strip_comments=True)
+ sql = sqlparse.format(sql.strip("\t\r\n; "), strip_comments=True)
if not sql:
raise QueryObjectValidationError(_("Virtual dataset query cannot be empty"))
if len(sqlparse.split(sql)) > 1:
|
Can we also add a unit test somewhere here: superset/tests/sqla_models_tests.py Line 226 in 609c359
You can create a new test case with |
Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>
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
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.
one comment, but lgtm otherwise. and thanks for adding the test!
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
…ix-sql-semicolon
* add method to strip semicolon * address comments * test the test * Update tests/sqla_models_tests.py Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> * Update tests/sqla_models_tests.py Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> * fix test * add suggestion * fix trailing space * remove logger * fix unit test Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
* add method to strip semicolon * address comments * test the test * Update tests/sqla_models_tests.py Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> * Update tests/sqla_models_tests.py Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> * fix test * add suggestion * fix trailing space * remove logger * fix unit test Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
* add method to strip semicolon * address comments * test the test * Update tests/sqla_models_tests.py Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> * Update tests/sqla_models_tests.py Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> * fix test * add suggestion * fix trailing space * remove logger * fix unit test Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
SUMMARY
This pr fixes the error when a sql statement in the datasource editor is ended with semicolon. It would cause an error in explore.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
Create a virtual datasource query and and save the dataset. Then click on the datasource to land in explore and the chart panel should not give any error.
ADDITIONAL INFORMATION