Skip to content

Commit 7536dd1

Browse files
fix(charts): Time grain is None when dataset uses Jinja (#25842)
1 parent 30cd422 commit 7536dd1

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

superset-frontend/packages/superset-ui-core/src/query/normalizeTimeColumn.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ export function normalizeTimeColumn(
7070
};
7171
}
7272

73-
const newQueryObject = omit(queryObject, [
74-
'extras.time_grain_sqla',
75-
'is_timeseries',
76-
]);
73+
const newQueryObject = omit(queryObject, ['is_timeseries']);
7774
newQueryObject.columns = mutatedColumns;
7875

7976
return newQueryObject;

superset-frontend/packages/superset-ui-core/test/query/normalizeTimeColumn.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ describe('GENERIC_CHART_AXES is disabled', () => {
9292
datasource: '5__table',
9393
viz_type: 'table',
9494
granularity: 'time_column',
95-
extras: {},
95+
extras: {
96+
time_grain_sqla: 'P1Y',
97+
},
9698
time_range: '1 year ago : 2013',
9799
orderby: [['count(*)', true]],
98100
columns: [
@@ -182,7 +184,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
182184
datasource: '5__table',
183185
viz_type: 'table',
184186
granularity: 'time_column',
185-
extras: { where: '', having: '' },
187+
extras: { where: '', having: '', time_grain_sqla: 'P1Y' },
186188
time_range: '1 year ago : 2013',
187189
orderby: [['count(*)', true]],
188190
columns: [
@@ -240,7 +242,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
240242
datasource: '5__table',
241243
viz_type: 'table',
242244
granularity: 'time_column',
243-
extras: { where: '', having: '' },
245+
extras: { where: '', having: '', time_grain_sqla: 'P1Y' },
244246
time_range: '1 year ago : 2013',
245247
orderby: [['count(*)', true]],
246248
columns: [

superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ test('should convert a queryObject with x-axis although FF is disabled', () => {
307307
extras: {
308308
having: '',
309309
where: "(foo in ('a', 'b'))",
310+
time_grain_sqla: 'P1W',
310311
},
311312
applied_time_extras: {},
312313
columns: [

superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/buildQuery.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
120120
expect.objectContaining({
121121
granularity: 'time_column',
122122
time_range: '1 year ago : 2013',
123-
extras: { having: '', where: '' },
123+
extras: { having: '', where: '', time_grain_sqla: 'P1Y' },
124124
columns: [
125125
{
126126
columnType: 'BASE_AXIS',
@@ -209,7 +209,7 @@ describe('GENERIC_CHART_AXES is disabled', () => {
209209
expect.objectContaining({
210210
granularity: 'time_column',
211211
time_range: '1 year ago : 2013',
212-
extras: { having: '', where: '' },
212+
extras: { having: '', where: '', time_grain_sqla: 'P1Y' },
213213
columns: [
214214
{
215215
columnType: 'BASE_AXIS',

superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import omit from 'lodash/omit';
20-
2119
import {
2220
AdhocColumn,
2321
buildQueryContext,
@@ -72,9 +70,7 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
7270
}
7371
return [
7472
{
75-
...(hasGenericChartAxes
76-
? omit(baseQueryObject, ['extras.time_grain_sqla'])
77-
: baseQueryObject),
73+
...baseQueryObject,
7874
orderby: orderBy,
7975
columns,
8076
},

superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,16 @@ test('should fallback to formData.time_grain_sqla if extra_form_data.time_grain_
121121
expressionType: 'SQL',
122122
});
123123
});
124+
125+
test('should not omit extras.time_grain_sqla from queryContext so dashboards apply them', () => {
126+
Object.defineProperty(supersetCoreModule, 'hasGenericChartAxes', {
127+
value: true,
128+
});
129+
const modifiedFormData = {
130+
...formData,
131+
extra_form_data: { time_grain_sqla: TimeGranularity.QUARTER },
132+
};
133+
const queryContext = buildQuery(modifiedFormData);
134+
const [query] = queryContext.queries;
135+
expect(query.extras?.time_grain_sqla).toEqual(TimeGranularity.QUARTER);
136+
});

0 commit comments

Comments
 (0)