You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2026/09/21 16:39:14 UTC
(superset) branch fix-semantic-layer-post-processing-typeerror created (now eab66ee4410)
This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a change to branch fix-semantic-layer-post-processing-typeerror
in repository https://gitbox.apache.org/repos/asf/superset.git
at eab66ee4410 fix(semantic-layer): wrap raw pandas TypeError/DataError from post-processing as QueryObjectValidationError
This branch includes the following new commits:
new eab66ee4410 fix(semantic-layer): wrap raw pandas TypeError/DataError from post-processing as QueryObjectValidationError
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix(semantic-layer): wrap raw pandas TypeError/DataError from post-processing as QueryObjectValidationError
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a commit to branch fix-semantic-layer-post-processing-typeerror
in repository https://gitbox.apache.org/repos/asf/superset.git
commit eab66ee4410937c3b7b4bde067c7abc2f9f0c604
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Mon Sep 21 16:38:52 2026 +0000
fix(semantic-layer): wrap raw pandas TypeError/DataError from post-processing as QueryObjectValidationError
SemanticView.get_query_result caught only InvalidPostProcessingError from
query_object.exec_post_processing, so a raw pandas TypeError (or
pandas.errors.DataError) — e.g. resample().mean() on a result set that
carries an object-dtype dimension alongside numeric metrics — propagated as
an opaque 500 instead of the project's normal 400 QueryObjectValidationError.
Widen the catch to also translate TypeError/DataError, mirroring the fix for
the sibling ExploreMixin.get_query_result path in apache/superset#44463.
Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
superset/semantic_layers/models.py | 3 ++
tests/unit_tests/semantic_layers/models_test.py | 45 +++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/superset/semantic_layers/models.py b/superset/semantic_layers/models.py
index c0f81e34591..dbb9eba1ce3 100644
--- a/superset/semantic_layers/models.py
+++ b/superset/semantic_layers/models.py
@@ -27,6 +27,7 @@ from dataclasses import dataclass
from functools import cached_property
from typing import Any, TYPE_CHECKING
+import pandas as pd
import pyarrow as pa
import sqlalchemy as sa
from flask_appbuilder import Model
@@ -375,6 +376,8 @@ class SemanticView(AuditMixinNullable, Model):
result.df = query_object.exec_post_processing(result.df)
except InvalidPostProcessingError as ex:
raise QueryObjectValidationError(ex.message) from ex
+ except (TypeError, pd.errors.DataError) as ex:
+ raise QueryObjectValidationError(str(ex)) from ex
return result
def get_query_str(self, query_obj: QueryObjectDict) -> str:
diff --git a/tests/unit_tests/semantic_layers/models_test.py b/tests/unit_tests/semantic_layers/models_test.py
index ff201c469e9..e260476310f 100644
--- a/tests/unit_tests/semantic_layers/models_test.py
+++ b/tests/unit_tests/semantic_layers/models_test.py
@@ -1002,6 +1002,51 @@ def test_semantic_view_get_query_result_wraps_post_processing_errors(
view.get_query_result(mock_query_object)
+def test_semantic_view_get_query_result_wraps_post_processing_type_error(
+ mock_implementation: MagicMock,
+) -> None:
+ """
+ A raw ``TypeError`` from pandas inside ``exec_post_processing`` (e.g.
+ ``resample.mean()`` on a DataFrame that carries an object-dtype column
+ alongside numeric metrics — a normal real-world query result) must be
+ surfaced as ``QueryObjectValidationError`` (400) rather than propagating
+ as a system 500, matching the dataset flow in
+ ``superset/models/helpers.py`` (apache/superset#44463).
+ """
+ import pandas as pd
+
+ from superset.common.query_object import QueryObject
+ from superset.exceptions import QueryObjectValidationError
+
+ view = SemanticView()
+
+ # DatetimeIndex + object-dtype "category" column makes
+ # ``df.resample("1D").mean()`` raise a raw TypeError in pandas >= 2.x.
+ df = pd.DataFrame(
+ {"metric": [1.0, 2.0], "category": ["a", "b"]},
+ index=pd.to_datetime(["2023-01-01", "2023-01-03"]),
+ )
+
+ query_object = QueryObject(
+ row_limit=10,
+ post_processing=[
+ {"operation": "resample", "options": {"method": "mean", "rule": "1D"}}
+ ],
+ )
+
+ mock_result = MagicMock()
+ mock_result.df = df
+
+ with (
+ patch(
+ "superset.semantic_layers.models.get_results",
+ return_value=mock_result,
+ ),
+ pytest.raises(QueryObjectValidationError),
+ ):
+ view.get_query_result(query_object)
+
+
def test_semantic_view_get_query_result_skips_post_processing_on_empty_df(
mock_implementation: MagicMock,
) -> None: