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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to