mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
feat(chart): Enable caching per user when user impersonation is enabled (#20114)
* add username to extra cache keys when impersonation is enabled.
* don't put effective_user in extra_cache_key
* get_impersonation_key method in engine_spec class to construct an impersonation key
* pass datasource when creating query objects
* adding an impersonation key when construction cache key
* add feature flag to control caching per user
* revert changes
* make precommit and pylint happy
* pass a User instance
* remove unnecessary import
(cherry picked from commit 68af5980ea)
This commit is contained in:
committed by
Michael S. Molina
parent
4841e8fb9c
commit
59fbf2a202
@@ -23,9 +23,11 @@ from datetime import datetime, timedelta
|
||||
from pprint import pformat
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, TYPE_CHECKING
|
||||
|
||||
from flask import g
|
||||
from flask_babel import gettext as _
|
||||
from pandas import DataFrame
|
||||
|
||||
from superset import feature_flag_manager
|
||||
from superset.common.chart_data import ChartDataResultType
|
||||
from superset.exceptions import (
|
||||
InvalidPostProcessingError,
|
||||
@@ -396,6 +398,24 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||
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(
|
||||
getattr(g, "user", None)
|
||||
):
|
||||
|
||||
logger.debug(
|
||||
"Adding impersonation key to QueryObject cache dict: %s", key
|
||||
)
|
||||
|
||||
cache_dict["impersonation_key"] = key
|
||||
|
||||
return md5_sha_from_dict(cache_dict, default=json_int_dttm_ser, ignore_nan=True)
|
||||
|
||||
def exec_post_processing(self, df: DataFrame) -> DataFrame:
|
||||
|
||||
Reference in New Issue
Block a user