rusackas commented on code in PR #42938:
URL: https://github.com/apache/superset/pull/42938#discussion_r3744963384
##########
superset/utils/rls.py:
##########
@@ -181,6 +182,12 @@ def collect_rls_predicates_for_sql(
}
)
except Exception:
- # If we can't parse the SQL, return empty list
- # This ensures RLS application failure doesn't break caching
- return []
+ # If we can't parse the SQL, we can't tell which (if any) RLS
+ # predicates would apply, so we can't contribute a meaningful cache
+ # key component. Returning an empty list here would make every
+ # user's failure collapse onto the same (missing) contribution,
+ # which is unsafe when different users have different RLS scopes on
+ # the underlying tables. Fall back to a per-user marker instead, so
+ # the cache key still varies by user even though we don't know the
+ # actual predicates.
+ return [f"rls-predicate-parse-failed-for-user-{get_user_id()}"]
Review Comment:
Good catch, `get_user_id()` returns `None` for guest users so different
guest tokens were colliding on the same sentinel. Now hashing the guest token's
own `rls_rules` instead so distinct scopes stay separate.
##########
superset/commands/database/sync_permissions.py:
##########
@@ -313,14 +318,14 @@ def _rename_database_in_permissions(
@celery_app.task(name="sync_database_permissions", soft_time_limit=600)
def sync_database_permissions_task(
- database_id: int, username: str, old_db_connection_name: str
+ database_id: int, user_id: int, old_db_connection_name: str
Review Comment:
This only bites during the exact rolling-deploy window in async mode, and
the failure is just a skipped sync that reruns cleanly on the next update, not
corrupted state. Don't think that's worth versioning the task for.
##########
superset/utils/rls.py:
##########
@@ -181,6 +182,12 @@ def collect_rls_predicates_for_sql(
}
)
except Exception:
- # If we can't parse the SQL, return empty list
- # This ensures RLS application failure doesn't break caching
- return []
+ # If we can't parse the SQL, we can't tell which (if any) RLS
+ # predicates would apply, so we can't contribute a meaningful cache
+ # key component. Returning an empty list here would make every
+ # user's failure collapse onto the same (missing) contribution,
+ # which is unsafe when different users have different RLS scopes on
+ # the underlying tables. Fall back to a per-user marker instead, so
+ # the cache key still varies by user even though we don't know the
+ # actual predicates.
+ return [f"rls-predicate-parse-failed-for-user-{get_user_id()}"]
Review Comment:
The suggested diff doesn't actually narrow the catch, it's the same `except
Exception`. Keeping it broad here is intentional, sqlglot can raise all sorts
of exception types on malformed SQL and the fallback needs to fire regardless.
--
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]