Skip to content

Commit cc714f9

Browse files
authored
fix: Skip rendering empty SQL dashboard filter (#2115)
## Summary This PR fixes a bug causing the $__filters macro to error when the dashboard's global SQL filter is an empty string or whitespace only. ### Screenshots or video Before: an empty string in the SQL filter box would cause $__filters to render as `(())` <img width="1708" height="1042" alt="Screenshot 2026-04-14 at 1 29 41 PM" src="https://github.com/user-attachments/assets/0a4068ad-eaf2-4bf7-b894-b796f642b59a" /> After: the empty SQL filter is ignored <img width="2330" height="520" alt="Screenshot 2026-04-14 at 1 29 20 PM" src="https://github.com/user-attachments/assets/a1e83091-5522-4745-b717-f1bf51c84a80" /> ### How to test locally or on Vercel This can be tested in the preview environment ### References - Linear Issue: Closes HDX-4017 - Related PRs:
1 parent 28f374e commit cc714f9

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

.changeset/sharp-emus-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
---
4+
5+
fix: Skip rendering empty SQL dashboard filter

packages/common-utils/src/__tests__/renderChartConfig.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,25 @@ describe('renderChartConfig', () => {
19891989
);
19901990
});
19911991

1992+
it('skips empty sql filters when source has no tableName (metric source)', async () => {
1993+
const result = await renderChartConfig(
1994+
{
1995+
configType: 'sql',
1996+
sqlTemplate: 'SELECT * FROM logs WHERE $__filters',
1997+
connection: 'conn-1',
1998+
dateRange: [start, end],
1999+
source: 'source-1',
2000+
from: { databaseName: 'default', tableName: '' },
2001+
filters: [{ type: 'sql', condition: '' }],
2002+
},
2003+
mockMetadata,
2004+
undefined,
2005+
);
2006+
expect(result.sql).toBe(
2007+
'SELECT * FROM logs WHERE (1=1 /** no filters applied */)',
2008+
);
2009+
});
2010+
19922011
it('skips filters without source metadata (no from)', async () => {
19932012
const result = await renderChartConfig(
19942013
{

packages/common-utils/src/core/renderChartConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,9 @@ async function renderFiltersToSql(
15421542
if (filter.type === 'sql_ast') {
15431543
return `(${filter.left} ${filter.operator} ${filter.right})`;
15441544
} else if (filter.type === 'sql' && !hasSourceTable) {
1545-
return `(${filter.condition})`; // Don't pass to renderWhereExpressionStr since it requires source table metadata
1545+
return filter.condition.trim()
1546+
? `(${filter.condition})` // Don't pass to renderWhereExpressionStr since it requires source table metadata
1547+
: undefined;
15461548
} else if (
15471549
(filter.type === 'lucene' || filter.type === 'sql') &&
15481550
filter.condition.trim() &&

0 commit comments

Comments
 (0)