From commits-return-667-archive-asf-public=cust-asf.ponee.io@superset.incubator.apache.org Mon Feb 19 01:30:20 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 03BA118064D for ; Mon, 19 Feb 2018 01:30:19 +0100 (CET) Received: (qmail 68352 invoked by uid 500); 19 Feb 2018 00:30:19 -0000 Mailing-List: contact commits-help@superset.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@superset.incubator.apache.org Delivered-To: mailing list commits@superset.incubator.apache.org Received: (qmail 68343 invoked by uid 99); 19 Feb 2018 00:30:19 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Feb 2018 00:30:19 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id DE4948216F; Mon, 19 Feb 2018 00:30:17 +0000 (UTC) Date: Mon, 19 Feb 2018 00:30:17 +0000 To: "commits@superset.apache.org" Subject: [incubator-superset] branch master updated: Remove comments from queries in SQL Lab that break Explore view (#4413) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151900021774.31677.12296307689895860555@gitbox.apache.org> From: maximebeauchemin@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-superset X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: f46bb533cb6265b54d319137ec4e7d731dab98aa X-Git-Newrev: d6c197f8acfa016eccc7a624251841829a14e5f6 X-Git-Rev: d6c197f8acfa016eccc7a624251841829a14e5f6 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-superset.git The following commit(s) were added to refs/heads/master by this push: new d6c197f Remove comments from queries in SQL Lab that break Explore view (#4413) d6c197f is described below commit d6c197f8acfa016eccc7a624251841829a14e5f6 Author: Ville Brofeldt <33317356+villebro@users.noreply.github.com> AuthorDate: Mon Feb 19 02:30:11 2018 +0200 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) --- superset/connectors/sqla/models.py | 1 + tests/core_tests.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index b2e21c7..9e2ae20 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -428,6 +428,7 @@ class SqlaTable(Model, BaseDatasource): from_sql = template_processor.process_template(from_sql) if db_engine_spec: from_sql = db_engine_spec.escape_sql(from_sql) + from_sql = sqlparse.format(from_sql, strip_comments=True) return TextAsFrom(sa.text(from_sql), []).alias('expr_qry') return self.get_sqla_table() diff --git a/tests/core_tests.py b/tests/core_tests.py index a026ae4..aa5c361 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -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() -- To stop receiving notification emails like this one, please contact maximebeauchemin@apache.org.