bito-code-review[bot] commented on code in PR #44526:
URL: https://github.com/apache/superset/pull/44526#discussion_r4095614567
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>unhashable dict crash</b></div>
<div id="fix">
`granularity_sqla` can be an adhoc dict (see
`migrations/shared/migrate_viz/base.py:135`), so `legacy_granularity in
temporal_columns` (a set of str) raises `TypeError: unhashable type: 'dict'` on
legacy charts replayed through this path. Guard with
`isinstance(legacy_granularity, str)` before the membership test.
</div>
</div>
<small><i>Code Review Run #37a027</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]