Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: fixing async syntax for python 3.7 #5759

Merged
merged 3 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

def execute(cursor, query, async_=False, **kwargs):

(See my comment above.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this one be def execute(cursor, query, **kwargs):? Then downstream systems like PyHive can specify async_?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we had def execute(cursor, query, **kwargs): here then the method would have to be like this:

def execute(cursor, query, **kwargs):
    kwargs['async'] = kwargs.pop('async_', False)
    cursor.execute(query, **kwargs) 

Since SQL Lab is passing async_=True, but PyHive expects an async named argument. We're basically mapping the keyword argument from async_ to async, as it's passed from SQL Lab to PyHive.

I prefer having it explicitly named in the function signature instead:

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

This way if you're looking at this line in sql_lab.py:

https://github.com/apache/incubator-superset/blob/be04c98cd3a55aec9c9dd6d1457de5655ad20b30/superset/sql_lab.py#L175

You can grep and find which function takes the async (async_) argument.

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