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 2022/06/08 17:30:18 UTC

[GitHub] [superset] betodealmeida commented on a diff in pull request #20114: feat(chart): Enable caching per user when user impersonation is enabled

betodealmeida commented on code in PR #20114:
URL: https://github.com/apache/superset/pull/20114#discussion_r892671019


##########
superset/common/query_object.py:
##########
@@ -396,6 +398,24 @@ def cache_key(self, **extra: Any) -> str:
         if annotation_layers:
             cache_dict["annotation_layers"] = annotation_layers
 
+        # Add an impersonation key to cache if impersonation is enabled on the db
+        if (
+            feature_flag_manager.is_feature_enabled("CACHE_IMPERSONATION")
+            and self.datasource
+            and hasattr(self.datasource, "database")
+            and self.datasource.database.impersonate_user
+        ):
+
+            if key := self.datasource.database.db_engine_spec.get_impersonation_key(
+                get_username()

Review Comment:
   Passing the user object here instead of the username makes the method more flexible, since other DBs might want to use the ID or the email. You can simply do:
   
   ```suggestion
                   getattr(g, "user", None)
   ```
   
   And add `from flask import g` to the top of the file.



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