You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/01/11 01:30:34 UTC

[GitHub] timifasubaa closed pull request #6497: pass source to db api mutator

timifasubaa closed pull request #6497: pass source to db api mutator
URL: https://github.com/apache/incubator-superset/pull/6497
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/models/core.py b/superset/models/core.py
index 97dd54a400..e9b1918d1c 100644
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -757,7 +757,7 @@ def get_effective_user(self, url, user_name=None):
 
     @utils.memoized(
         watch=('impersonate_user', 'sqlalchemy_uri_decrypted', 'extra'))
-    def get_sqla_engine(self, schema=None, nullpool=True, user_name=None):
+    def get_sqla_engine(self, schema=None, nullpool=True, user_name=None, source=None):
         extra = self.get_extra()
         url = make_url(self.sqlalchemy_uri_decrypted)
         url = self.db_engine_spec.adjust_database_uri(url, schema)
@@ -790,7 +790,7 @@ def get_sqla_engine(self, schema=None, nullpool=True, user_name=None):
         DB_CONNECTION_MUTATOR = config.get('DB_CONNECTION_MUTATOR')
         if DB_CONNECTION_MUTATOR:
             url, params = DB_CONNECTION_MUTATOR(
-                url, params, effective_username, security_manager)
+                url, params, effective_username, security_manager, source)
         return create_engine(url, **params)
 
     def get_reserved_words(self):
@@ -801,7 +801,14 @@ def get_quoter(self):
 
     def get_df(self, sql, schema):
         sqls = [str(s).strip().strip(';') for s in sqlparse.parse(sql)]
-        engine = self.get_sqla_engine(schema=schema)
+        source_key = None
+        if request and request.referrer:
+            if '/superset/dashboard/' in request.referrer:
+                source_key = 'dashboard'
+            elif '/superset/explore/' in request.referrer:
+                source_key = 'chart'
+        engine = self.get_sqla_engine(
+            schema=schema, source=utils.sources.get(source_key, None))
         username = utils.get_username()
 
         def needs_conversion(df_series):
@@ -860,7 +867,8 @@ def select_star(
             self, table_name, schema=None, limit=100, show_cols=False,
             indent=True, latest_partition=False, cols=None):
         """Generates a ``select *`` statement in the proper dialect"""
-        eng = self.get_sqla_engine(schema=schema)
+        eng = self.get_sqla_engine(
+            schema=schema, source=utils.sources.get('sql_lab', None))
         return self.db_engine_spec.select_star(
             self, table_name, schema=schema, engine=eng,
             limit=limit, show_cols=show_cols,
diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 63de7830fa..28ad921908 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -20,6 +20,7 @@
 from superset.utils.core import (
     json_iso_dttm_ser,
     QueryStatus,
+    sources,
     zlib_compress,
 )
 from superset.utils.dates import now_as_float
@@ -226,6 +227,7 @@ def execute_sql_statements(
         schema=query.schema,
         nullpool=True,
         user_name=user_name,
+        source=sources.get('sql_lab', None),
     )
     # Sharing a single connection and cursor across the
     # execution of all statements (if many)
diff --git a/superset/utils/core.py b/superset/utils/core.py
index b1b81e56d2..5bf3054651 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -54,6 +54,12 @@
 
 JS_MAX_INTEGER = 9007199254740991   # Largest int Java Script can handle 2^53-1
 
+sources = {
+    'chart': 0,
+    'dashboard': 1,
+    'sql_lab': 2,
+}
+
 
 def flasher(msg, severity=None):
     """Flask's flash if available, logging call if not"""


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org