Skip to content
Merged
16 changes: 12 additions & 4 deletions superset/common/query_context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def _apply_granularity(

if granularity := query_object.granularity:
filter_to_remove = None
if x_axis and x_axis in temporal_columns:
x_axis_column_name = (
x_axis["sqlExpression"] if isinstance(x_axis, dict) else x_axis
)
Comment thread
zephyring marked this conversation as resolved.
Outdated
if x_axis_column_name in temporal_columns:
filter_to_remove = x_axis
x_axis_column = next(
(
Expand All @@ -137,7 +140,7 @@ def _apply_granularity(
if column == x_axis
or (
isinstance(column, dict)
and column["sqlExpression"] == x_axis
and column["sqlExpression"] == x_axis_column_name
)
),
None,
Expand Down Expand Up @@ -175,11 +178,16 @@ def _apply_granularity(
# another temporal filter. A new filter based on the value of
# the granularity will be added later in the code.
# In practice, this is replacing the previous default temporal filter.
if filter_to_remove:
filter_to_remove_str = (
filter_to_remove["sqlExpression"]
if isinstance(filter_to_remove, dict)
else filter_to_remove
)
if filter_to_remove_str:
query_object.filter = [
filter
for filter in query_object.filter
if filter["col"] != filter_to_remove
if filter["col"] != filter_to_remove_str
]

def _apply_filters(self, query_object: QueryObject) -> None:
Expand Down