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 2021/07/22 13:41:51 UTC

[GitHub] [superset] jgluna opened a new issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

jgluna opened a new issue #15836:
URL: https://github.com/apache/superset/issues/15836


   When DB_CONNECTION_MUTATOR is called for SqlLab the g object is empty
   
   ### Expected results
   
   After adding this DB_CONNECTION_MUTATOR to superset_config.py the current username should be used in the connection string
   
   ```
   def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
       logger.info("mutator working")
       logger.info("g")
       logger.info(g)
       logger.info(g.__dict__)
       logger.info("username")
       logger.info(username)
       logger.info("source")
       logger.info(source)
       uri.username = g.user.username
       logger.info(uri)
   
       return uri, params
   ```
   
   ### Actual results
   
   The g object is empty when getting the connection for the actual query execution in SqlLab, it works well everywhere else.
   
   Here is an extract of the logs
   
   ```//Loading schemas and tables
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{'user': <redacted>}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   INFO:superset_config:<vertica+vertica_python://<g.user.username>:<password>@<db_host>
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{'user': <redacted}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   INFO:superset_config:<vertica+vertica_python://<g.user.username>:<password>@<db_host>
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{'user': <redacted>}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   INFO:superset_config:<vertica+vertica_python://<g.user.username>:<password>@<db_host>
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{'user': <redacted>}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   INFO:superset_config:<vertica+vertica_python://<g.user.username>:<password>@<db_host>
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{'user': <redacted>}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   INFO:superset_config:<vertica+vertica_python://<g.user.username>:<password>@<db_host>
   
   //Running the actual query
   Triggering query_id: 11
   INFO:superset.views.core:Triggering query_id: 11
   Query 11: Executing 1 statement(s)
   INFO:superset.sql_lab:Query 11: Executing 1 statement(s)
   Query 11: Set query to 'running'
   INFO:superset.sql_lab:Query 11: Set query to 'running'
   INFO:superset_config:mutator working
   INFO:superset_config:g
   INFO:superset_config:<flask.g of 'superset.app'>
   INFO:superset_config:{}
   INFO:superset_config:username
   INFO:superset_config:None
   INFO:superset_config:source
   INFO:superset_config:QuerySource.SQL_LAB
   '_AppCtxGlobals' object has no attribute 'user'
   WARNING:superset.views.base:'_AppCtxGlobals' object has no attribute 'user'
   ```
   #### How to reproduce the bug
   
   1. Add the connection mutator to superset_config.py
   2. Go to SqlLab option
   3. Select your database connection, schema and tables
   4. Click the `Run` button
   5. A `DB engine Error '_AppCtxGlobals' object has no attribute 'user'` error will be shown
   6. Take a look at the logs and they should resemble the ones I posted
   
   ### Environment
   
   (please complete the following information):
   
   - superset version: 1.1.0
   - python version: 3.8.9
   
   ### Checklist
   
   Make sure to follow these steps before submitting your issue - thank you!
   
   - [x] I have checked the superset logs for python stacktraces and included it here as text if there are any.
   - [x] I have reproduced the issue with at least the latest released version of superset.
   - [x] I have checked the issue tracker for the same issue and I haven't found one similar.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna closed issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna closed issue #15836:
URL: https://github.com/apache/superset/issues/15836


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna closed issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna closed issue #15836:
URL: https://github.com/apache/superset/issues/15836


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna commented on issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna commented on issue #15836:
URL: https://github.com/apache/superset/issues/15836#issuecomment-885032933


   after adding a `logger.info(dir(g))` in the mutator i got this:
   
   - attributes before clicking the run button
   ```
   INFO:superset_config:['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get', 'pop', 'setdefault', 'user']
   ```
   - attributes after clicking the run button
   ```
   INFO:superset_config:['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get', 'pop', 'setdefault']
   ```
   user is completely gone when the 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna commented on issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna commented on issue #15836:
URL: https://github.com/apache/superset/issues/15836#issuecomment-885266569


   Hi @rumbin, thanks, that did the trick!!
   
   Here is a simple mutator for whoever run into this in the future, just add this in your superset_config.py and when you create the Database connection make sure to enable `Advanced->Other->Impersonate Logged In User`
   
   ```def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
       logger.info("mutator working")
       logger.info("username")
       logger.info(username)
   
       uri.username = username
       logger.info(uri)
   
       return uri, params```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] rumbin commented on issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
rumbin commented on issue #15836:
URL: https://github.com/apache/superset/issues/15836#issuecomment-885241325


   We ran into somewhat similar troubles when trying to use the security_manager argument. It worked in Explore and Dashboards, bit not in the SQLLab Celery workers. I don't know if this information is helpful for you, but for us using the username argument did the trick. However, it took us quite some time to figure out that this attribute only gets populated if the user Inpersonation checkbox is set to True in the DB Connection configuration (although this is labeled to be intended for Hive and Presto, it also helped is for Snowflake).
   The username can then be used to query the security_manager. This even works for SQLLab.
   Hope this is at least a bit helpful...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna edited a comment on issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna edited a comment on issue #15836:
URL: https://github.com/apache/superset/issues/15836#issuecomment-885032933


   after adding a `logger.info(dir(g))` in the mutator i got this:
   
   - attributes before clicking the run button
   ```
   INFO:superset_config:['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get', 'pop', 'setdefault', 'user']
   ```
   - attributes after clicking the run button
   ```
   INFO:superset_config:['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get', 'pop', 'setdefault']
   ```
   user is completely gone from the g object when the `Run query` is clicked


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [superset] jgluna edited a comment on issue #15836: g object empty whe DB_CONNECTION_MUTATOR is called in SqlLab

Posted by GitBox <gi...@apache.org>.
jgluna edited a comment on issue #15836:
URL: https://github.com/apache/superset/issues/15836#issuecomment-885266569


   Hi @rumbin, thanks, that did the trick!!
   
   Here is a simple mutator for whoever run into this in the future, just add this in your superset_config.py and when you create the Database connection make sure to enable `Advanced->Other->Impersonate Logged In User`
   
   ```
   def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
       logger.info("mutator working")
       logger.info("username")
       logger.info(username)
   
       uri.username = username
       logger.info(uri)
   
       return uri, params
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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