zephyring commented on code in PR #23021:
URL: https://github.com/apache/superset/pull/23021#discussion_r1309449085
##########
superset/common/query_context_factory.py:
##########
@@ -99,3 +103,89 @@ def _convert_to_model(self, datasource: DatasourceDict) ->
BaseDatasource:
def _get_slice(self, slice_id: Any) -> Optional[Slice]:
return ChartDAO.find_by_id(slice_id)
+
+ def _process_query_object(
+ self,
+ datasource: BaseDatasource,
+ form_data: Optional[Dict[str, Any]],
+ query_object: QueryObject,
+ ) -> QueryObject:
+ self._apply_granularity(query_object, form_data, datasource)
+ self._apply_filters(query_object)
+ return query_object
+
+ def _apply_granularity(
+ self,
+ query_object: QueryObject,
+ form_data: Optional[Dict[str, Any]],
+ datasource: BaseDatasource,
+ ) -> None:
+ temporal_columns = {
+ column.column_name
+ for column in datasource.columns
+ if (column["is_dttm"] if isinstance(column, dict) else
column.is_dttm)
+ }
+ granularity = query_object.granularity
+ x_axis = form_data and form_data.get("x_axis")
+
+ if granularity:
+ filter_to_remove = None
+ if x_axis and x_axis in temporal_columns:
Review Comment:
hey @michael-s-molina we recently found a regression where the `x_axis`
could be a `dict` while `temporal_columns` is a set of string and it throws.
Steps to reproduce:
```
1. Create a Bar Chart using the Vehicle Sales dataset.
2. Use Custom SQL for the X-Axis field and type in order_date.
3. Use SUM(price_each) for the Metrics field.
4. Use the SQL Lab to duplicate the Vehicle Sales dataset.
5. Perform a dataset swap to the duplicated Vehicle Sales dataset.
6. Update and Save the chart.
```
I am trying to use `x_axis["sqlExpression"]` to get the proper str to
compare down the road and it doesn't seem to have the same effect.
Would love your thoughts here thanks!
--
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]