This is an automated email from the ASF dual-hosted git repository.
johnbodley 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 7fcc2af [sql] Correct SQL parameter formatting (#5178)
7fcc2af is described below
commit 7fcc2af68f79a8a78e1799feb80647ae90ac9370
Author: John Bodley <4567245+john-bod...@users.noreply.github.com>
AuthorDate: Sat Jul 21 12:01:26 2018 -0700
[sql] Correct SQL parameter formatting (#5178)
---
.pylintrc | 2 +-
superset/connectors/sqla/models.py | 9 +--
superset/db_engine_specs.py| 12 ++-
.../4451805bbaa1_remove_double_percents.py | 86 ++
superset/models/core.py| 43 +++
superset/sql_lab.py| 3 +-
tests/core_tests.py| 9 +++
tests/sqllab_tests.py | 2 +-
tox.ini| 2 +-
9 files changed, 138 insertions(+), 30 deletions(-)
diff --git a/.pylintrc b/.pylintrc
index 820637d..016b04e 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -282,7 +282,7 @@
ignored-modules=numpy,pandas,alembic.op,sqlalchemy,alembic.context,flask_appbuil
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
-ignored-classes=optparse.Values,thread._local,_thread._local,sqlalchemy.orm.scoping.scoped_session
+ignored-classes=contextlib.closing,optparse.Values,thread._local,_thread._local,sqlalchemy.orm.scoping.scoped_session
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
diff --git a/superset/connectors/sqla/models.py
b/superset/connectors/sqla/models.py
index 3c5b18e..c86d4ea 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -12,7 +12,6 @@ from flask import escape, Markup
from flask_appbuilder import Model
from flask_babel import lazy_gettext as _
import pandas as pd
-import six
import sqlalchemy as sa
from sqlalchemy import (
and_, asc, Boolean, Column, DateTime, desc, ForeignKey, Integer, or_,
@@ -427,14 +426,8 @@ class SqlaTable(Model, BaseDatasource):
table=self, database=self.database, **kwargs)
def get_query_str(self, query_obj):
-engine = self.database.get_sqla_engine()
qry = self.get_sqla_query(**query_obj)
-sql = six.text_type(
-qry.compile(
-engine,
-compile_kwargs={'literal_binds': True},
-),
-)
+sql = self.database.compile_sqla_query(qry)
logging.info(sql)
sql = sqlparse.format(sql, reindent=True)
if query_obj['is_prequery']:
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 97b8095..2b74541 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -65,7 +65,6 @@ class BaseEngineSpec(object):
"""Abstract class for database engine specific configurations"""
engine = 'base' # str as defined in sqlalchemy.engine.engine
-cursor_execute_kwargs = {}
time_grains = tuple()
time_groupby_inline = False
limit_method = LimitMethod.FORCE_LIMIT
@@ -331,6 +330,10 @@ class BaseEngineSpec(object):
def normalize_column_name(column_name):
return column_name
+@staticmethod
+def execute(cursor, query, async=False):
+cursor.execute(query)
+
class PostgresBaseEngineSpec(BaseEngineSpec):
""" Abstract class for Postgres 'like' databases """
@@ -558,7 +561,6 @@ class SqliteEngineSpec(BaseEngineSpec):
class MySQLEngineSpec(BaseEngineSpec):
engine = 'mysql'
-cursor_execute_kwargs = {'args': {}}
time_grains = (
Grain('Time Column', _('Time Column'), '{col}', None),
Grain('second', _('second'), 'DATE_ADD(DATE({col}), '
@@ -639,7 +641,6 @@ class MySQLEngineSpec(BaseEngineSpec):
class PrestoEngineSpec(BaseEngineSpec):
engine = 'presto'
-cursor_execute_kwargs = {'parameters': None}
time_grains = (
Grain('Time Column', _('Time Column'), '{col}', None),
@@ -938,7 +939,6 @@ class HiveEngineSpec(PrestoEngineSpec):
"""Reuses PrestoEngineSpec functionality."""
engine = 'hive'
-cursor_execute_kwargs = {'async': True}
# Scoping regex at class level to avoid recompiling
# 17/02/07 19:36:38 INFO ql.Driver: Total jobs = 5
@@ -1230,6 +1230,10 @@ class HiveEngineSpec(PrestoEngineSpec):
configuration['hive.server2.proxy.user'] = username
return configuration
+@staticmethod
+def execute(cursor, query, async=False):
+cursor.execute(query, async=async)
+
class MssqlEngine