mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: add new cache_query_by_user key (#23415)
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
This commit is contained in:
committed by
GitHub
parent
ffc0a81e85
commit
b021f6e05d
@@ -397,20 +397,24 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||
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(
|
||||
getattr(g, "user", None)
|
||||
):
|
||||
logger.debug(
|
||||
"Adding impersonation key to QueryObject cache dict: %s", key
|
||||
)
|
||||
# or if the CACHE_QUERY_BY_USER flag is on
|
||||
try:
|
||||
database = self.datasource.database # type: ignore
|
||||
if (
|
||||
feature_flag_manager.is_feature_enabled("CACHE_IMPERSONATION")
|
||||
and database.impersonate_user
|
||||
) or feature_flag_manager.is_feature_enabled("CACHE_QUERY_BY_USER"):
|
||||
if key := database.db_engine_spec.get_impersonation_key(
|
||||
getattr(g, "user", None)
|
||||
):
|
||||
logger.debug(
|
||||
"Adding impersonation key to QueryObject cache dict: %s", key
|
||||
)
|
||||
|
||||
cache_dict["impersonation_key"] = key
|
||||
cache_dict["impersonation_key"] = key
|
||||
except AttributeError:
|
||||
# datasource or database do not exist
|
||||
pass
|
||||
|
||||
return md5_sha_from_dict(cache_dict, default=json_int_dttm_ser, ignore_nan=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user