This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 7fea33761b8 fix(chart): wrap raw pandas TypeError/DataError from
post-processing as QueryObjectValidationError (#44463)
7fea33761b8 is described below
commit 7fea33761b8986f3f0ca653ad46c30da0fa47f49
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Fri Oct 2 15:01:26 2026 -0700
fix(chart): wrap raw pandas TypeError/DataError from post-processing as
QueryObjectValidationError (#44463)
---
superset/models/helpers.py | 2 ++
tests/unit_tests/models/helpers_test.py | 51 +++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 47e10c8b708..de1df53923a 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -2683,6 +2683,8 @@ class ExploreMixin: # pylint:
disable=too-many-public-methods
df = query_object.exec_post_processing(df)
except InvalidPostProcessingError as ex:
raise QueryObjectValidationError(ex.message) from ex
+ except (TypeError, pd.errors.DataError) as ex:
+ raise QueryObjectValidationError(str(ex)) from ex
# Update result with processed data
result.df = df
diff --git a/tests/unit_tests/models/helpers_test.py
b/tests/unit_tests/models/helpers_test.py
index 6990fd008c1..f24a109605c 100644
--- a/tests/unit_tests/models/helpers_test.py
+++ b/tests/unit_tests/models/helpers_test.py
@@ -5777,3 +5777,54 @@ def test_filter_adhoc_column(database: Database) -> None:
# The adhoc column resolved by label is parenthesized in the WHERE clause,
# consistent with inline adhoc columns, to guard operator precedence.
assert "lower((real_name)) LIKE lower('Zona%')" in sql
+
+
+def test_get_query_result_wraps_post_processing_type_error(
+ database: "Database",
+) -> None:
+ """
+ A raw TypeError from pandas inside exec_post_processing (e.g.
resample.mean()
+ on a DataFrame that contains object-dtype columns) must be surfaced as
+ QueryObjectValidationError (400) rather than propagating as a system 500.
+ """
+ from datetime import timedelta
+ from unittest.mock import patch
+
+ import pandas as pd
+
+ from superset.common.query_object import QueryObject
+ from superset.connectors.sqla.models import SqlaTable
+ from superset.exceptions import QueryObjectValidationError
+ from superset.models.helpers import QueryResult
+
+ table = SqlaTable(table_name="t", database=database)
+
+ # DatetimeIndex + object-dtype "category" column causes
+ # df.resample("1D").mean() to raise 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"}}
+ ],
+ )
+
+ with (
+ patch.object(
+ table,
+ "query",
+ return_value=QueryResult(
+ df=df,
+ query="SELECT 1",
+ duration=timedelta(0),
+ sql_shifted_temporal_labels=set(),
+ ),
+ ),
+ patch.object(table, "normalize_df", return_value=df),
+ pytest.raises(QueryObjectValidationError),
+ ):
+ table.get_query_result(query_object)