superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [sql_json] allow not specifying client_id (#5730)
Date Thu, 06 Sep 2018 05:34:27 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 5616d7b  [sql_json] allow not specifying client_id (#5730)
5616d7b is described below

commit 5616d7bdd72cb6d41caaf8733823d5d7dbe26abb
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Sep 5 22:34:24 2018 -0700

    [sql_json] allow not specifying client_id (#5730)
    
    * [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
---
 superset/utils.py      | 4 ++++
 superset/views/core.py | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/superset/utils.py b/superset/utils.py
index 8480b17..96c1f13 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -1018,3 +1018,7 @@ def get_username():
 
 def MediumText():
     return Text().with_variant(MEDIUMTEXT(), 'mysql')
+
+
+def shortid():
+    return '{}'.format(uuid.uuid4())[-12:]
diff --git a/superset/views/core.py b/superset/views/core.py
index 97a7da9..1e02292 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2402,6 +2402,8 @@ class Superset(BaseSupersetView):
                 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),
@@ -2413,8 +2415,8 @@ class Superset(BaseSupersetView):
             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()),
-            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()


Mime
View raw message