rickysaltzer commented on issue #20455:
URL: https://github.com/apache/superset/issues/20455#issuecomment-1218275478

   I think the following is a suitable workaround:
   
   `models/core.py#392` 
   ```python
           if DB_CONNECTION_MUTATOR:
               if not source and request and request.referrer:
                   if "/superset/dashboard/" in request.referrer:
                       source = utils.QuerySource.DASHBOARD
                   elif "/superset/explore/" in request.referrer:
                       source = utils.QuerySource.CHART
                   elif "/superset/sqllab/" in request.referrer:
                       source = utils.QuerySource.SQL_LAB
   
               if source == utils.QuerySource.SQL_LAB:
                   effective_username = user_name
   
               # if SQL_LAB is set, use the user_name
               sqlalchemy_url, params = DB_CONNECTION_MUTATOR(
                   sqlalchemy_url, params, effective_username, 
security_manager, source
               )
   ```
   
   `DB_CONNECTION_MUTATOR`
   ```python
   def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
       # The following just accesses the user from the SAM, but does not 
actually set it.
       # - the same behavior occurs if you access `g` directly.
       if username and source is QuerySource.SQL_LAB:
           user = security_manager.find_user(username=username)
       else:
           user = security_manager.current_user
       if user:
           uri.username = user.username
           uri.password = "password"
       return uri, params
   ```
   
   The key is that `user_name` is passed to the model when the user hits the 
`Run` box, and can be passed to the mutator for a user lookup...as the 
`current_user` is unavailable to the mutator when `Run` is clicked. I've only 
tested this locally, but it appears to work 😄 


-- 
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