msyavuz commented on code in PR #36309:
URL: https://github.com/apache/superset/pull/36309#discussion_r2576990092


##########
superset/models/helpers.py:
##########
@@ -1698,31 +1698,32 @@ def _get_temporal_column_for_filter(  # noqa: C901
         Helper method to reliably determine the temporal column for filtering.
 
         This method tries multiple strategies to find the correct temporal 
column:
-        1. Use explicitly set granularity
-        2. Use x_axis_label if it's a temporal column
-        3. Find any datetime column in the datasource
+        1. Use the column from existing TEMPORAL_RANGE filter
+        2. Use explicitly set granularity
+        3. Use x_axis_label if it exists
 
         :param query_object: The query object
         :param x_axis_label: The x-axis label from the query
         :return: The name of the temporal column, or None if not found
         """
-        # Strategy 1: Use explicitly set granularity
+        # Strategy 1: Use the column from existing TEMPORAL_RANGE filter
+        if query_object.filter:
+            for flt in query_object.filter:
+                if flt.get("op") == FilterOperator.TEMPORAL_RANGE:
+                    col = flt.get("col")
+                    if isinstance(col, str):
+                        return col
+                    elif isinstance(col, dict) and col.get("sqlExpression"):
+                        return str(col.get("label") or 
col.get("sqlExpression"))

Review Comment:
   Hey, AdhocColumn type is a dict containing label and no name. That's why i 
am checking it here. If the payload doesn't match the type we should do the 
update there but i don't think that would be the case.
   ```py
   class AdhocColumn(TypedDict, total=False):
       hasCustomLabel: bool | None
       label: str
       sqlExpression: str
       isColumnReference: bool | None
       columnType: Literal["BASE_AXIS", "SERIES"] | None
       timeGrain: str | None
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to