This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch fix-query-cache
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/fix-query-cache by this push:
     new 3da13cafb9 Lint
3da13cafb9 is described below

commit 3da13cafb98b9c36a7fbed4f605a1ef576914e4e
Author: Beto Dealmeida <[email protected]>
AuthorDate: Tue Oct 7 17:03:21 2025 -0400

    Lint
---
 superset/common/query_object.py |  3 ++-
 superset/models/helpers.py      | 16 +++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/superset/common/query_object.py b/superset/common/query_object.py
index 1a9116fd2d..cd6d60d8de 100644
--- a/superset/common/query_object.py
+++ b/superset/common/query_object.py
@@ -193,7 +193,8 @@ class QueryObject:  # pylint: 
disable=too-many-instance-attributes
             return isinstance(metric, str) or is_adhoc_metric(metric)
 
         self.metrics = metrics and [
-            x if is_str_or_adhoc(x) else x["label"] for x in metrics  # type: 
ignore
+            x if is_str_or_adhoc(x) else x["label"]
+            for x in metrics  # type: ignore
         ]
 
     def _set_post_processing(
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index d4347e5e93..8192c16748 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -1819,14 +1819,15 @@ class ExploreMixin:  # pylint: 
disable=too-many-public-methods
         for metric in metrics:
             if utils.is_adhoc_metric(metric):
                 assert isinstance(metric, dict)
-                # SQL expressions are already processed during 
QueryObject.validate()
-                # via _sanitize_sql_expressions()
+                # SQL expressions are sanitized during QueryObject.validate() 
via
+                # _sanitize_sql_expressions(), but we still process here to 
handle
+                # Jinja templates. sanitize_clause() is idempotent so 
re-sanitizing
+                # is safe.
                 metrics_exprs.append(
                     self.adhoc_metric_to_sqla(
                         metric=metric,
                         columns_by_name=columns_by_name,
                         template_processor=template_processor,
-                        processed=True,
                     )
                 )
             elif isinstance(metric, str) and metric in metrics_by_name:
@@ -1858,15 +1859,16 @@ class ExploreMixin:  # pylint: 
disable=too-many-public-methods
             col: Union[AdhocMetric, ColumnElement] = orig_col
             if isinstance(col, dict):
                 col = cast(AdhocMetric, col)
-                # SQL expressions are already processed during 
QueryObject.validate()
-                # via _sanitize_sql_expressions(), so we pass processed=True 
to skip
-                # re-processing and avoid mutation
+                # SQL expressions are sanitized during QueryObject.validate() 
via
+                # _sanitize_sql_expressions(). We still process here to handle
+                # Jinja templates. The removal of the 
_process_orderby_expression()
+                # call (which mutated the dict) prevents cache key mismatches.
                 if utils.is_adhoc_metric(col):
                     # add adhoc sort by column to columns_by_name if not exists
                     col = self.adhoc_metric_to_sqla(
                         col,
                         columns_by_name,
-                        processed=True,
+                        template_processor=template_processor,
                     )
                     # use the existing instance, if possible
                     col = metrics_exprs_by_expr.get(str(col), col)

Reply via email to