Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/sim/app/api/cron/cleanup-stale-executions/route.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,10 +245,14 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
= (${asyncJobs.metadata}->>'maxDurationSeconds')::numeric
ELSE FALSE
END`
// A bare `Date` in a raw template reaches the driver unserialized; `sql.param`
// binds it through the column encoder, as `lt(column, date)` does elsewhere here.
const staleProcessingCutoff = sql.param(now, asyncJobs.startedAt)
const staleProcessingFallbackCutoff = sql.param(staleThreshold, asyncJobs.startedAt)
const staleProcessingDurationPredicate = sql<boolean>`CASE
WHEN ${hasPositiveMaxDuration}
THEN ${asyncJobs.startedAt} + ((${asyncJobs.metadata}->>'maxDurationSeconds')::double precision * interval '1 second') < ${now}
ELSE ${asyncJobs.startedAt} < ${staleThreshold}
THEN ${asyncJobs.startedAt} + ((${asyncJobs.metadata}->>'maxDurationSeconds')::double precision * interval '1 second') < ${staleProcessingCutoff}
ELSE ${asyncJobs.startedAt} < ${staleProcessingFallbackCutoff}
END`
const staleProcessingPredicate = and(
eq(asyncJobs.status, JOB_STATUS.PROCESSING),
Expand Down
10 changes: 10 additions & 0 deletions packages/testing/src/mocks/database.mock.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,16 @@ import { vi } from 'vitest'
*/
export function createMockSql() {
const sqlFn = (strings: TemplateStringsArray, ...values: any[]) => {
// Same hazard as `sql.param(date)` below, and the form that actually shipped:
// an interpolated `Date` carries no column context, so drizzle skips
// `PgTimestamp.mapToDriverValue` and postgres-js receives a Date it cannot serialize.
if (values.some((value) => value instanceof Date)) {
throw new Error(
'sql`…${date}` interpolates a Date without an encoder, which reaches ' +
'postgres-js as a Date object its unsafe path cannot serialize. Bind ' +
'through the matching column: sql.param(date, table.timestampColumn).'
)
}
const fragment = {
strings,
values,
Expand Down
Loading