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 lab] improve error messages (#3308)
Date Fri, 18 Aug 2017 22:50:09 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 6fc837d  [sql lab] improve error messages (#3308)
6fc837d is described below

commit 6fc837db51cf4d9bafff19862da7b045e57388e8
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Fri Aug 18 15:50:07 2017 -0700

    [sql lab] improve error messages (#3308)
    
    * [sql lab] improve error messages
    
    Some error messages in non-async mode were showing as JSON or sometimes
    as tuples. This fixes that.
    
    * linting
---
 superset/data/__init__.py   |  6 +++---
 superset/db_engine_specs.py | 11 +++++++++++
 superset/sql_lab.py         |  2 +-
 superset/views/base.py      | 12 ++++++------
 superset/views/core.py      |  5 ++---
 5 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/superset/data/__init__.py b/superset/data/__init__.py
index c3428b3..2671a3f 100644
--- a/superset/data/__init__.py
+++ b/superset/data/__init__.py
@@ -950,10 +950,10 @@ def load_random_time_series_data():
 
 def load_country_map_data():
     """Loading data for map with country map"""
-    csvPath = os.path.join(DATA_FOLDER, 'birth_france_data_for_country_map.csv')
-    data = pd.read_csv(csvPath, encoding="utf-8")
+    csv_path = os.path.join(DATA_FOLDER, 'birth_france_data_for_country_map.csv')
+    data = pd.read_csv(csv_path, encoding="utf-8")
     data['date'] = datetime.datetime.now().date()
-    data.to_sql(
+    data.to_sql(  # pylint: disable=no-member
         'birth_france_by_region',
         db.engine,
         if_exists='replace',
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 0fe9889..8ff8ef7 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -351,6 +351,17 @@ class MySQLEngineSpec(BaseEngineSpec):
     def epoch_to_dttm(cls):
         return "from_unixtime({col})"
 
+    @classmethod
+    def extract_error_message(cls, e):
+        """Extract error message for queries"""
+        message = str(e)
+        try:
+            if isinstance(e.args, tuple) and len(e.args) > 1:
+                message = e.args[1]
+        except:
+            pass
+        return message
+
 
 class PrestoEngineSpec(BaseEngineSpec):
     engine = 'presto'
diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 1d0e892..06954ad 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -120,7 +120,7 @@ def execute_sql(ctask, query_id, return_results=True, store_results=False):
         session.commit()
         payload.update({
             'status': query.status,
-            'error_essage': msg,
+            'error': msg,
         })
         return payload
 
diff --git a/superset/views/base.py b/superset/views/base.py
index 6974f71..02aaf8d 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -31,13 +31,13 @@ def get_error_msg():
     return error_msg
 
 
-def json_error_response(msg, status=None, stacktrace=None):
-    data = {'error': str(msg)}
-    if stacktrace:
-        data['stacktrace'] = stacktrace
-    status = status if status else 500
+def json_error_response(msg=None, status=500, stacktrace=None, payload=None):
+    if not payload:
+        payload = {'error': str(msg)}
+        if stacktrace:
+            payload['stacktrace'] = stacktrace
     return Response(
-        json.dumps(data),
+        json.dumps(payload, default=utils.json_iso_dttm_ser),
         status=status, mimetype="application/json")
 
 
diff --git a/superset/views/core.py b/superset/views/core.py
index 98a0aa6..65d3feb 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2074,13 +2074,12 @@ class Superset(BaseSupersetView):
                 # pylint: disable=no-value-for-parameter
                 data = sql_lab.get_sql_results(
                     query_id=query_id, return_results=True)
-                payload = json.dumps(data, default=utils.json_iso_dttm_ser)
         except Exception as e:
             logging.exception(e)
             return json_error_response("{}".format(e))
         if data.get('status') == QueryStatus.FAILED:
-            return json_error_response(payload)
-        return json_success(payload)
+            return json_error_response(payload=data)
+        return json_success(json.dumps(data, default=utils.json_iso_dttm_ser))
 
     @has_access
     @expose("/csv/<client_id>")

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message