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

Conversation

xtinec
Copy link
Contributor

@xtinec xtinec commented Aug 28, 2018

Rename async to async_ so superset installs for python 3.7. 👀 @betodealmeida

Rename async to async_ so superset installs for python 3.7.
@codecov-io
Copy link

codecov-io commented Aug 28, 2018

Codecov Report

Merging #5759 into master will increase coverage by 0.02%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5759      +/-   ##
==========================================
+ Coverage   63.34%   63.36%   +0.02%     
==========================================
  Files         364      364              
  Lines       23051    23051              
  Branches     2565     2565              
==========================================
+ Hits        14602    14607       +5     
+ Misses       8434     8429       -5     
  Partials       15       15
Impacted Files Coverage Δ
superset/sql_lab.py 71.77% <100%> (ø) ⬆️
superset/db_engine_specs.py 54.01% <33.33%> (-0.15%) ⬇️
superset/views/core.py 74.29% <0%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60ecd72...0dabf00. Read the comment docs.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

This turned out to be more complicated than I expected! I'll make a quick PR to Pyhive to fix their side.

self.login()
resp = self.client.post(
'/superset/sql_json/',
data=dict(
database_id=db_id,
sql=sql,
async=async,
async_=async_,
Copy link
Member

Choose a reason for hiding this comment

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

Here we're POSTing the data payload into the sql_json view, so this should actually be runAsync=async_. See: https://github.com/apache/incubator-superset/blob/60ecd72aac85b8faddeeb339f24299224ecbca91/superset/views/core.py#L2375

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

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

Here the async_ keyword argument is not being used anywhere. The reason why it's here is because some engines (actually, only HiveEngineSpec) have the async option and override this method. SQL Lab doesn't differentiate between engines, and regardless of the backend will call:

db_engine_spec.execute(cursor, query.executed_sql, async_=True)

It's better to change the method signature here to:

def execute(cls, cursor, query, **kwargs):

This way, any extra keyword arguments are stored in kwargs, and derived classes can declare more specific signatures, eg, for HiveEngineSpec:

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

@@ -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):
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.

def execute(cursor, query, async=False):
cursor.execute(query, async=async)
def execute(cursor, query, async_=False):
cursor.execute(query, async_=async_)
Copy link
Member

Choose a reason for hiding this comment

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

Here, cursor is a pyhive cursor, and unfortunately it expects a keyword argument called async: https://github.com/dropbox/PyHive/blob/65076bbc8697a423b438dc03e928a6dff86fd2cb/pyhive/hive.py#L337

There's an open issue to address this: dropbox/PyHive#148 Unfortunately, until they fix it, we won't be able to run Hive queries in Superset under Python 3.7. :(

In the meantime, I would recommend changing this to:

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

This will allow Superset to work with Python 3.7 with other engines, and with Hive when using Python < 3.7.

Copy link
Member

Choose a reason for hiding this comment

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

For reference: dropbox/PyHive#232

…sync_ so downstream engines (e.g. PyHive) that supports async can choose to use the async_ in pythonwq3.7 and async in <=python3.6
if cls.arraysize:
cursor.arraysize = cls.arraysize
cursor.execute(query)
cursor.execute(query, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

This should actually be just:

cursor.execute(query)

Otherwise when SQL Lab calls:

db_engine_spec.execute(cursor, query.executed_sql, async_=True)

The async_ kwarg will be passed down to all the cursors, and this could potentially cause an exception if their method signatures don't have **kwargs.

def execute(cursor, query, async=False):
cursor.execute(query, async=async)
def execute(cursor, query, **kwargs):
cursor.execute(query, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

This won't work as is, since your PR changes SQL Lab to pass the async_ keyword to the execute method, and PyHive is (still) expecting the async keyword. You need to map the async_ that you receive from SQL Lab into async for PyHive, see two approaches in this comment: #5759

(Sorry if this is confusing, this is a bit of Python black magic...)

@betodealmeida betodealmeida merged commit ae3fb04 into apache:master Aug 29, 2018
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* 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
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Oct 29, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* 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)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* 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)
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* 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
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants