fix(drill-to-detail): ensure axis label filters map to original column names (#34694)

Co-authored-by: bito-code-review[bot] <188872107+bito-code-review[bot]@users.noreply.github.com>
This commit is contained in:
LisaHusband
2025-09-10 23:18:37 +08:00
committed by GitHub
parent 7a20a65a4d
commit a7d349a5c6
2 changed files with 131 additions and 1 deletions

View File

@@ -14,7 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any, Optional
import logging
from typing import Any, Iterable, Optional
from flask import current_app as app
@@ -27,6 +28,8 @@ from superset.daos.datasource import DatasourceDAO
from superset.utils.core import QueryStatus
from superset.views.datasource.schemas import SamplesPayloadSchema
logger = logging.getLogger(__name__)
def get_limit_clause(page: Optional[int], per_page: Optional[int]) -> dict[str, int]:
samples_row_limit = app.config.get("SAMPLES_ROW_LIMIT", 1000)
@@ -44,6 +47,47 @@ def get_limit_clause(page: Optional[int], per_page: Optional[int]) -> dict[str,
return {"row_offset": offset, "row_limit": limit}
def replace_verbose_with_column(
filters: list[dict[str, Any]],
columns: Iterable[Any],
verbose_attr: str = "verbose_name",
column_attr: str = "column_name",
) -> None:
"""
Replace filter 'col' values that match column verbose_name with the column_name.
Operates in-place on the filters list
Args:
filters: List of filter dicts, each must have 'col' key.
columns: Iterable of column objects with verbose_name and column_name.
verbose_attr: Attribute name for verbose/label.
column_attr: Attribute name for actual column name.
"""
for f in filters:
col_value = f.get("col")
if col_value is None:
logger.warning("Filter missing 'col' key: %s", f)
continue
match = None
for col in columns:
if not hasattr(col, verbose_attr) or not hasattr(col, column_attr):
logger.warning(
"Column object %s missing expected attributes '%s' or '%s'",
col,
verbose_attr,
column_attr,
)
continue
if getattr(col, verbose_attr) == col_value:
match = getattr(col, column_attr)
break
if match:
f["col"] = match
def get_samples( # pylint: disable=too-many-arguments
datasource_type: str,
datasource_id: int,
@@ -72,6 +116,9 @@ def get_samples( # pylint: disable=too-many-arguments
force=force,
)
else:
# Use column names replacing verbose column names(Label)
replace_verbose_with_column(payload.get("filters", []), datasource.columns)
# constructing drill detail query
# When query_type == 'samples' the `time filter` will be removed,
# so it is not applicable drill detail query