bmaquet commented on code in PR #32770:
URL: https://github.com/apache/superset/pull/32770#discussion_r2006006986


##########
superset/jinja_context.py:
##########
@@ -172,6 +174,20 @@ def current_user_email(self, add_to_cache_keys: bool = 
True) -> Optional[str]:
             return email_address
         return None
 
+    def current_user_roles(self, add_to_cache_keys: bool = True) -> str | None:
+        """
+        Return the roles of the user who is currently logged in.
+
+        :param add_to_cache_keys: Whether the value should be included in the 
cache key
+        :returns: List of role names as a JSON string
+        """
+
+        if user_roles := get_user_roles():
+            if add_to_cache_keys:
+                self.cache_key_wrapper(json.dumps(user_roles))

Review Comment:
   For two reasons:
   1. without `json.dumps`, SQL cannot render correctly when calling the macro 
(see screenshot)
   <img width="1089" alt="Screenshot 2025-03-20 at 16 59 36" 
src="https://github.com/user-attachments/assets/1cb0daaf-5ca0-4c06-9834-d9a971062bbb";
 />
   2. when `add_to_cache_keys` is True, we add the value of `user_roles` into 
the cache, as a cache key. If `user_roles` was a list this would raise ` 
TypeError: unhashable type: 'list'`
   
   If needed, users can still use JSON functions to parse the results



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