bito-code-review[bot] commented on code in PR #44526:
URL: https://github.com/apache/superset/pull/44526#discussion_r4124547461


##########
superset/common/query_context_factory.py:
##########
@@ -275,6 +275,27 @@ def _apply_granularity(  # noqa: C901
             query_object.granularity = main_dttm_col
             return
 
+        # A ``query_context`` saved by an older version carries no
+        # ``granularity`` of its own and no x-axis at all: its temporal column
+        # survives only in ``form_data`` as ``granularity_sqla``. Explore
+        # rebuilds the query from ``form_data`` on every render and never
+        # notices, but every other consumer replays the stored query verbatim
+        # and fails the ``not granularity and is_timeseries`` check in
+        # ``models.helpers``. The absent x-axis is what distinguishes this 
shape
+        # from a modern chart, so it is tested first. Recover the column the 
way
+        # Explore effectively does, preferring what the chart saved over the
+        # dataset default.
+        if (
+            not x_axis
+            and query_object.granularity is None
+            and query_object.is_timeseries
+        ):
+            legacy_granularity = (form_data or {}).get("granularity_sqla") or 
getattr(
+                datasource, "main_dttm_col", None
+            )
+            if legacy_granularity in temporal_columns:
+                query_object.granularity = legacy_granularity

Review Comment:
   <!-- Bito Reply -->
   The suggestion to guard the membership test with 
`isinstance(legacy_granularity, str)` is appropriate. It prevents a `TypeError` 
when `granularity_sqla` is an adhoc dictionary, ensuring the code safely 
handles legacy chart configurations.
   
   **superset/common/query_context_factory.py**
   ```
   legacy_granularity = (form_data or {}).get("granularity_sqla") or getattr(
                   datasource, "main_dttm_col", None
               )
               if isinstance(legacy_granularity, str) and legacy_granularity in 
temporal_columns:
                   query_object.granularity = legacy_granularity
   ```



-- 
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