mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Remove comments from queries in SQL Lab that break Explore view (#4413)
* Remove comments from queries in SQL Lab that break Explore view This fixes an issue where comments on the last line of the source query comment out the closing parenthesis of the subquery. * Add test case for SqlaTable with query with comment This test ensures that comments in the query are removed when calling SqlaTable.get_from_clause(). * Add missing blank line class definition (PEP8)
This commit is contained in:
committed by
Maxime Beauchemin
parent
f46bb533cb
commit
d6c197f8ac
@@ -18,6 +18,7 @@ import unittest
|
||||
from flask import escape
|
||||
import pandas as pd
|
||||
import psycopg2
|
||||
from six import text_type
|
||||
import sqlalchemy as sqla
|
||||
|
||||
from superset import appbuilder, dataframe, db, jinja_context, sm, sql_lab, utils
|
||||
@@ -870,6 +871,13 @@ class CoreTests(SupersetTestCase):
|
||||
{'data': pd.Timestamp('2017-11-18 22:06:30.061810+0100', tz=tz)},
|
||||
)
|
||||
|
||||
def test_comments_in_sqlatable_query(self):
|
||||
clean_query = "SELECT '/* val 1 */' as c1, '-- val 2' as c2 FROM tbl"
|
||||
commented_query = '/* comment 1 */' + clean_query + '-- comment 2'
|
||||
table = SqlaTable(sql=commented_query)
|
||||
rendered_query = text_type(table.get_from_clause())
|
||||
self.assertEqual(clean_query, rendered_query)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user