dosubot[bot] commented on issue #30168:
URL: https://github.com/apache/superset/issues/30168#issuecomment-2332542465

   <!-- Greeting -->
   Hey there, @dmarkey! I'm here to help you with any bugs, questions, or 
contributions you have for Apache Superset. Let's tackle this issue together!
   
   <!-- Answer -->
   The issue you're encountering with `flask_login.current_user` being `None` 
during the execution of `SQL_QUERY_MUTATOR` in SQLLab sessions is due to 
differences in the execution context between SQLLab and navigating graphs. In 
SQLLab sessions, the user ID is explicitly retrieved and stored in the 
`SqlJsonExecutionContext` class using the `get_user_id()` function, rather than 
relying on `flask_login.current_user` directly 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/sqllab/sqllab_execution_context.py)</sup>.
   
   To work around this, you can modify your `SQL_QUERY_MUTATOR` to use the 
`get_user_id()` function to retrieve the user ID. Here’s an example:
   
   ```python
   from superset.utils.core import get_user_id
   
   def SQL_QUERY_MUTATOR(sql: str, **kwargs) -> str:
       user_id = get_user_id()
       print(user_id)  # This should print the correct user ID during a SQLLab 
session
       return sql
   ```
   
   This approach ensures that you get the correct user information even in the 
SQLLab context.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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-unsubscr...@superset.apache.org

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


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

Reply via email to