Skip to content

Commit

Permalink
Bug: fixing async syntax for python 3.7 (apache#5759)
Browse files Browse the repository at this point in the history
* Bug: fixing async syntax for python 3.7

Rename async to async_ so superset installs for python 3.7.

* Addressing PR comments. Use kwargs instead of explicitly specifying async_ so downstream engines (e.g. PyHive) that supports async can choose to use the async_ in pythonwq3.7 and async in <=python3.6

* addressing additional pr comments

(cherry picked from commit ae3fb04)
  • Loading branch information
xtinec authored and betodealmeida committed Oct 12, 2018
1 parent 67572c5 commit 111bf8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username):
return {}

@classmethod
def execute(cls, cursor, query, async=False):
def execute(cls, cursor, query, **kwargs):
if cls.arraysize:
cursor.arraysize = cls.arraysize
cursor.execute(query)
Expand Down Expand Up @@ -1276,8 +1276,9 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username):
return configuration

@staticmethod
def execute(cursor, query, async=False):
cursor.execute(query, async=async)
def execute(cursor, query, async_=False):
kwargs = {'async': async_}
cursor.execute(query, **kwargs)


class MssqlEngineSpec(BaseEngineSpec):
Expand Down
2 changes: 1 addition & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def handle_error(msg):
cursor = conn.cursor()
logging.info('Running query: \n{}'.format(executed_sql))
logging.info(query.executed_sql)
db_engine_spec.execute(cursor, query.executed_sql, async=True)
db_engine_spec.execute(cursor, query.executed_sql, async_=True)
logging.info('Handling cursor')
db_engine_spec.handle_cursor(cursor, query, session)
logging.info('Fetching data: {}'.format(query.to_dict()))
Expand Down
8 changes: 4 additions & 4 deletions tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def tearDownClass(cls):
)

def run_sql(self, db_id, sql, client_id, cta='false', tmp_table='tmp',
async='false'):
async_='false'):
self.login()
resp = self.client.post(
'/superset/sql_json/',
data=dict(
database_id=db_id,
sql=sql,
async=async,
runAsync=async_,
select_as_cta=cta,
tmp_table_name=tmp_table,
client_id=client_id,
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_run_async_query(self):
eng = main_db.get_sqla_engine()
sql_where = "SELECT name FROM ab_role WHERE name='Admin'"
result = self.run_sql(
main_db.id, sql_where, '4', async='true', tmp_table='tmp_async_1',
main_db.id, sql_where, '4', async_='true', tmp_table='tmp_async_1',
cta='true')
assert result['query']['state'] in (
QueryStatus.PENDING, QueryStatus.RUNNING, QueryStatus.SUCCESS)
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_run_async_query_with_lower_limit(self):
eng = main_db.get_sqla_engine()
sql_where = "SELECT name FROM ab_role WHERE name='Alpha' LIMIT 1"
result = self.run_sql(
main_db.id, sql_where, '5', async='true', tmp_table='tmp_async_2',
main_db.id, sql_where, '5', async_='true', tmp_table='tmp_async_2',
cta='true')
assert result['query']['state'] in (
QueryStatus.PENDING, QueryStatus.RUNNING, QueryStatus.SUCCESS)
Expand Down

0 comments on commit 111bf8e

Please sign in to comment.