superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Preprocess SQL Lab query prior to checking syntax (#4686)
Date Mon, 26 Mar 2018 16:42:36 GMT
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 4ec8258  Preprocess SQL Lab query prior to checking syntax (#4686)
4ec8258 is described below

commit 4ec82582c6c6e750a7bbd39b56a58fbaa81349c2
Author: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
AuthorDate: Mon Mar 26 19:42:33 2018 +0300

    Preprocess SQL Lab query prior to checking syntax (#4686)
    
    Syntax checking doesn't work if jinja templates haven't been prerendered.
    Also remove unreachable return statement. Fixes #4288.
---
 superset/sql_lab.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 12644fc..d28de7c 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -161,8 +161,18 @@ def execute_sql(
     if store_results and not results_backend:
         return handle_error("Results backend isn't configured.")
 
+    try:
+        template_processor = get_template_processor(
+            database=database, query=query)
+        tp = template_params or {}
+        rendered_query = template_processor.process_template(query.sql, **tp)
+    except Exception as e:
+        logging.exception(e)
+        msg = 'Template rendering failed: ' + utils.error_msg_from_exception(e)
+        return handle_error(msg)
+
     # Limit enforced only for retrieving the data, not for the CTA queries.
-    superset_query = SupersetQuery(query.sql)
+    superset_query = SupersetQuery(rendered_query)
     executed_sql = superset_query.stripped()
     if not superset_query.is_select() and not database.allow_dml:
         return handle_error(
@@ -172,7 +182,6 @@ def execute_sql(
             return handle_error(
                 'Only `SELECT` statements can be used with the CREATE TABLE '
                 'feature.')
-            return
         if not query.tmp_table_name:
             start_dttm = datetime.fromtimestamp(query.start_time)
             query.tmp_table_name = 'tmp_{}_table_{}'.format(
@@ -183,16 +192,6 @@ def execute_sql(
             db_engine_spec.limit_method == LimitMethod.WRAP_SQL):
         executed_sql = database.wrap_sql_limit(executed_sql, query.limit)
         query.limit_used = True
-    try:
-        template_processor = get_template_processor(
-            database=database, query=query)
-        tp = template_params or {}
-        executed_sql = template_processor.process_template(
-            executed_sql, **tp)
-    except Exception as e:
-        logging.exception(e)
-        msg = 'Template rendering failed: ' + utils.error_msg_from_exception(e)
-        return handle_error(msg)
 
     # Hook to allow environment-specific mutation (usually comments) to the SQL
     SQL_QUERY_MUTATOR = config.get('SQL_QUERY_MUTATOR')

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message