Skip to content

Commit

Permalink
fix(charts): Time grain is None when dataset uses Jinja
Browse files Browse the repository at this point in the history
- Ensure that extras.time_grain_sqla is not omitted when GENERIC_CHART_AXES is enabled to allow charts to correctly apply time grain when the underlying dataset uses Jinja.
  • Loading branch information
Antonio-RiveroMartnez committed Nov 2, 2023
1 parent 6ace22d commit c18d298
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ export function normalizeTimeColumn(
};
}

const newQueryObject = omit(queryObject, [
'extras.time_grain_sqla',
'is_timeseries',
]);
const newQueryObject = omit(queryObject, ['is_timeseries']);
newQueryObject.columns = mutatedColumns;

return newQueryObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import omit from 'lodash/omit';

import {
AdhocColumn,
buildQueryContext,
Expand Down Expand Up @@ -72,9 +70,7 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
}
return [
{
...(hasGenericChartAxes
? omit(baseQueryObject, ['extras.time_grain_sqla'])
: baseQueryObject),
...baseQueryObject,
orderby: orderBy,
columns,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ test('should fallback to formData.time_grain_sqla if extra_form_data.time_grain_
expressionType: 'SQL',
});
});

test('should not omit extras.time_grain_sqla from queryContext so dashboards apply them', () => {
Object.defineProperty(supersetCoreModule, 'hasGenericChartAxes', {
value: true,
});
const modifiedFormData = {
...formData,
extra_form_data: { time_grain_sqla: TimeGranularity.QUARTER },
};
const queryContext = buildQuery(modifiedFormData);
const [query] = queryContext.queries;
expect(query.extras?.time_grain_sqla).toEqual(TimeGranularity.QUARTER);
});

0 comments on commit c18d298

Please sign in to comment.