-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
SQL with inline comment starting with --
fails in dashboards view query
and sqllab
#29466
Comments
@PedroMartinSteenstrup Hello there! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's squash those bugs together! 😊 The issue you're encountering with SQL queries containing inline comments has been addressed in several pull requests, including #27725, #28363, #28567, and #29248. These changes ensure that comments are not stripped when executing SQL statements, which should resolve the errors you're seeing in both the dashboards' "view query" and SQL Lab. To fix the issue, ensure you are using the latest version of Superset where these fixes have been merged. Specifically, the changes in pull request #29248 should address the problem you're facing with inline comments starting with If you are already on the latest version and still experiencing issues, double-check your def sql_mutator(sql, security_manager, database):
from superset.utils.core import get_username
user_name = get_username()
q_suffix = f'Superset query context \'{{"user": "{user_name}"}}\''
return f"{sql} -- {q_suffix}" Make sure your Superset configuration includes this function and that SQL_QUERY_MUTATOR = sql_mutator
MUTATE_AFTER_SPLIT = False This should help resolve the errors related to inline comments in your SQL queries. |
good bot @dosu, setting Sadly, still a problem in sqllab, and I can now even more precisely point it out: That will work:
That will not work:
|
The issue with SQL Lab in Apache Superset when a SQL statement containing inline comments ends with a semicolon can be resolved by ensuring that the SQL statement is properly parsed and executed. The Here is the specific logic used in the def get_statements(self) -> list[str]:
"""Returns a list of SQL statements as strings, stripped"""
statements = []
for statement in self._parsed:
if statement:
sql = str(statement).strip(" \n;\t")
if sql:
statements.append(sql)
return statements This method strips any leading or trailing whitespace, newline characters, semicolons, and tabs from each statement, ensuring they are correctly parsed [1]. Additionally, there are known issues with the To further troubleshoot and resolve the issue, you can:
By following these steps, you should be able to resolve the issue with SQL Lab when a SQL statement containing inline comments ends with a semicolon. |
Bug description
Using sql_mutator to append a comment to queries such as
-- Superset query context '{"user": "superset.admin" }'
(dash dash followed by the object to parse later)Expecting value: line 1 column 1 (char 0)
Statement 2 out of 2 Only SELECT statements are allowed against this database.
Initially I've had
MUTATE_AFTER_SPLIT = False
.I've been using this "tagging" of queries for years, so I can definitely link it to something recent, and given the history of commits, I'm not sure what I should do: wait for a fix? or find another way to tag queries?
#29248
#28567
#28363
#27725
How to reproduce the bug
Or, go to a dashboard and try to
View Query
one chartSee results in screenshots
If I enable
MUTATE_AFTER_SPLIT = True
, then the dashboards can load and theView Query
functions. But running a sql query in SQLlab where one statement is commented out still does not function if the statement ends with;
(semicolon).Screenshots/recordings
Superset version
4.0.2 (apache/superset:4.0.2)
Python version
3.9
Node version
I don't know
Browser
Firefox 115.11.0esr
Gecko v0.34.0
Additional context
I am running 4.0.2 from published docker image, as I thought this would bring a fix from the change in behavior introduced when we upgraded to 4.0.1rc.
I could repeat the same error with Snowflake and Postgres databases.
Checklist
The text was updated successfully, but these errors were encountered: