villebro commented on code in PR #37941:
URL: https://github.com/apache/superset/pull/37941#discussion_r2804984253


##########
superset/security/manager.py:
##########
@@ -2701,6 +2701,17 @@ def get_rls_filters(self, table: "BaseDatasource | 
Explorable") -> list[SqlaQuer
         if not (hasattr(g, "user") and g.user is not None):
             return []
 
+        # Check request-scoped cache keyed by (user_identifier, table_id).
+        # Uses user_id for regular users and username for guest users.
+        cache: dict[tuple[int | str, int | str], list[SqlaQuery]] = getattr(

Review Comment:
   The dict type is a bit of a monster; can we add a type alias to describe 
what these mean? Something like this?
   ```python
   RequestUser = int | str
   RequestTable = int | str  # isn't this in fact just int?
   dict[tuple[RequestUser, RequestTable], list[SqlaQuery]]
   ```



##########
superset/security/manager.py:
##########
@@ -2701,6 +2701,17 @@ def get_rls_filters(self, table: "BaseDatasource | 
Explorable") -> list[SqlaQuer
         if not (hasattr(g, "user") and g.user is not None):
             return []
 
+        # Check request-scoped cache keyed by (user_identifier, table_id).
+        # Uses user_id for regular users and username for guest users.
+        cache: dict[tuple[int | str, int | str], list[SqlaQuery]] = getattr(
+            g, "_rls_filter_cache", {}
+        )
+        user_key: int | str | None = get_user_id() or getattr(g.user, 
"username", None)

Review Comment:
   Can't we just use `get_username()` from `superset.utils.core`? I mean don't 
all users have `username`, so we don't need to have either `id` or `username`, 
as we can key just with `username` which is `str | None`?



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