fix(charts): use separator-aware matching in renameOperator for time offsets

The `includes(offset)` substring match caused "11 year ago" to match
"1 year ago", producing duplicate column names that crash the backend
with "truth value of a Series is ambiguous". Switch to `endsWith` with
the `__` separator prefix for exact offset matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maxime Beauchemin
2026-04-21 03:24:41 +00:00
committed by Sophie
parent 194831d685
commit 5f40f5f1bb
2 changed files with 27 additions and 1 deletions

View File

@@ -67,7 +67,9 @@ export const renameOperator: PostProcessingFactory<PostProcessingRename> = (
[...metricOffsetMap.entries()].forEach(
([metricWithOffset, metricOnly]) => {
const offsetLabel = timeOffsets.find(offset =>
metricWithOffset.includes(offset),
metricWithOffset.endsWith(
`${TIME_COMPARISON_SEPARATOR}${offset}`,
),
);
renamePairs.push([
formData.comparison_type === ComparisonType.Values

View File

@@ -303,6 +303,30 @@ test('should add renameOperator if multiple metrics exist', () => {
});
});
test('should correctly match offsets that share a numeric prefix', () => {
expect(
renameOperator(
{
...formData,
comparison_type: ComparisonType.Values,
time_compare: ['1 year ago', '11 year ago'],
},
queryObject,
),
).toEqual({
operation: 'rename',
options: {
columns: {
'count(*)__1 year ago': '1 year ago',
'count(*)__11 year ago': '11 year ago',
},
inplace: true,
level: 0,
},
});
});
test('should remove renameOperator', () => {
expect(
renameOperator(