Skip to content

Commit

Permalink
[sql_json] allow not specifying client_id (apache#5730)
Browse files Browse the repository at this point in the history
* [sql_json] allow not specifying client_id

We're opening the sql_json endpoint at Lyft to other apps leveraging
Superset as a data-access layer that enforces authentication and our data
access policy.

Currently sql_json requires the client to pass a `client_id` parameter
that uniquely identifies the query, that can then be used for polling
when in async mode. This PR makes it such that you don't have to define
a client_id anymore. It just gets generated when not passed.

* adressing comments

(cherry picked from commit 5616d7b)
  • Loading branch information
mistercrunch committed Sep 14, 2018
1 parent bfab2d6 commit bb0c888
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,7 @@ def get_username():

def MediumText():
return Text().with_variant(MEDIUMTEXT(), 'mysql')


def shortid():
return '{}'.format(uuid.uuid4())[-12:]
6 changes: 4 additions & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,8 @@ def sql_json_call(self, request):
tmp_table_name,
)

client_id = request.form.get('client_id') or utils.shortid()

query = Query(
database_id=int(database_id),
limit=mydb.db_engine_spec.get_limit_from_sql(sql),
Expand All @@ -2418,8 +2420,8 @@ def sql_json_call(self, request):
status=QueryStatus.PENDING if async_ else QueryStatus.RUNNING,
sql_editor_id=request.form.get('sql_editor_id'),
tmp_table_name=tmp_table_name,
user_id=int(g.user.get_id()) if g.user and g.user.get_id() else None,
client_id=request.form.get('client_id'),
user_id=g.user.get_id() if g.user else None,
client_id=client_id,
)
session.add(query)
session.flush()
Expand Down

0 comments on commit bb0c888

Please sign in to comment.