Skip to content

Commit b972cce

Browse files
committed
fix(clickhouse): gate the compile-time downgrade on who wrote the query
The execution layer only downgrades when the caller wrote the SQL, but the compile-time catch downgraded every ExposedTSQLError regardless. A compile failure on TRQL we generated is our bug, and it was logging at warn. Whether an error is safe to show someone is a separate question from whose mistake it is, so the same gate now applies at both layers.
1 parent 23d8f3f commit b972cce

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

internal-packages/clickhouse/src/client/tsql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export async function executeTSQL<TOut extends z.ZodSchema>(
321321
generatedParams: generatedParams ?? {},
322322
};
323323

324-
const callerWroteABadQuery = error instanceof ExposedTSQLError;
324+
const callerWroteABadQuery = options.userAuthoredQuery && error instanceof ExposedTSQLError;
325325

326326
if (callerWroteABadQuery) {
327327
logger.warn("[TSQL] Invalid query", logFields);

internal-packages/clickhouse/src/tsql.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ describe("TSQL Error Log Levels", () => {
16421642
organization_id: { op: "eq", value: "org_tenant1" },
16431643
},
16441644
tableSchema: [taskRunsSchema],
1645+
userAuthoredQuery: true,
16451646
});
16461647

16471648
expect(error).not.toBeNull();
@@ -1663,6 +1664,7 @@ describe("TSQL Error Log Levels", () => {
16631664
organization_id: { op: "eq", value: "org_tenant1" },
16641665
},
16651666
tableSchema: [taskRunsSchema],
1667+
userAuthoredQuery: true,
16661668
});
16671669

16681670
expect(error).not.toBeNull();
@@ -1694,6 +1696,30 @@ describe("TSQL Error Log Levels", () => {
16941696
}
16951697
);
16961698

1699+
clickhouseTest(
1700+
"keeps a compile failure on TRQL we generated at error level",
1701+
async ({ clickhouseContainer }) => {
1702+
const client = new ClickhouseClient({
1703+
name: "test",
1704+
url: clickhouseContainer.getConnectionUrl(),
1705+
});
1706+
1707+
const [error] = await executeTSQL(client, {
1708+
name: "test-internal-compile-error",
1709+
query: "SELECT nope FROM task_runs",
1710+
schema: z.object({ nope: z.string() }),
1711+
enforcedWhereClause: {
1712+
organization_id: { op: "eq", value: "org_tenant1" },
1713+
},
1714+
tableSchema: [taskRunsSchema],
1715+
});
1716+
1717+
expect(error).not.toBeNull();
1718+
expect(logged(errorSpy)).toContain("[TSQL] Query error");
1719+
expect(logged(warnSpy)).not.toContain("[TSQL] Invalid query");
1720+
}
1721+
);
1722+
16971723
clickhouseTest(
16981724
"logs invalid caller-written SQL as a warning",
16991725
async ({ clickhouseContainer }) => {

0 commit comments

Comments
 (0)