From ed70f85c1bd9d9fde07e2d1501166997f0477263 Mon Sep 17 00:00:00 2001 From: Christine Chambers Date: Tue, 28 Aug 2018 11:33:42 -0700 Subject: [PATCH 1/3] Bug: fixing async syntax for python 3.7 Rename async to async_ so superset installs for python 3.7. --- superset/db_engine_specs.py | 6 +++--- superset/sql_lab.py | 2 +- tests/celery_tests.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 13eb69502bf51..a9f9ad6ee07d8 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -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, async_=False): if cls.arraysize: cursor.arraysize = cls.arraysize cursor.execute(query) @@ -1276,8 +1276,8 @@ 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): + cursor.execute(query, async_=async_) class MssqlEngineSpec(BaseEngineSpec): diff --git a/superset/sql_lab.py b/superset/sql_lab.py index a659653d37e76..4612b4e0ec8ce 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -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())) diff --git a/tests/celery_tests.py b/tests/celery_tests.py index 71adb2df43d1e..268d106a30562 100644 --- a/tests/celery_tests.py +++ b/tests/celery_tests.py @@ -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, + async_=async_, select_as_cta=cta, tmp_table_name=tmp_table, client_id=client_id, @@ -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) @@ -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) From 3a900bb79fc155ee3efda549ccd1b2d9db70de05 Mon Sep 17 00:00:00 2001 From: Christine Chambers Date: Tue, 28 Aug 2018 15:03:33 -0700 Subject: [PATCH 2/3] 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 --- superset/db_engine_specs.py | 8 ++++---- tests/celery_tests.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index a9f9ad6ee07d8..7fe930bb3d7f0 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -370,10 +370,10 @@ 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) + cursor.execute(query, **kwargs) @classmethod def adjust_df_column_names(cls, df, fd): @@ -1276,8 +1276,8 @@ 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, **kwargs): + cursor.execute(query, **kwargs) class MssqlEngineSpec(BaseEngineSpec): diff --git a/tests/celery_tests.py b/tests/celery_tests.py index 268d106a30562..243aacef4586d 100644 --- a/tests/celery_tests.py +++ b/tests/celery_tests.py @@ -130,7 +130,7 @@ def run_sql(self, db_id, sql, client_id, cta='false', tmp_table='tmp', 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, From 0dabf00595ffc36632ceb018377dae483b083b0d Mon Sep 17 00:00:00 2001 From: Christine Chambers Date: Tue, 28 Aug 2018 16:20:47 -0700 Subject: [PATCH 3/3] addressing additional pr comments --- superset/db_engine_specs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 7fe930bb3d7f0..2ce7db06bf1fd 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -373,7 +373,7 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username): def execute(cls, cursor, query, **kwargs): if cls.arraysize: cursor.arraysize = cls.arraysize - cursor.execute(query, **kwargs) + cursor.execute(query) @classmethod def adjust_df_column_names(cls, df, fd): @@ -1276,7 +1276,8 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username): return configuration @staticmethod - def execute(cursor, query, **kwargs): + def execute(cursor, query, async_=False): + kwargs = {'async': async_} cursor.execute(query, **kwargs)