Skip to content

Commit 2967cdb

Browse files
committed
fix(run-store): fix batch idempotency lookup on the dedicated run-ops store
findRunsByIdempotencyKeys built its UNION ALL of per-key point-lookups with @trigger.dev/database's Prisma.sql/Prisma.join and then ran it on whichever store client it was handed. On the dedicated run-ops store that client is a separate generated Prisma client, and a Sql from a different generated client is not recognized: the bare $queryRaw(Prisma.join(...)) form dropped the query text ("Argument query is missing"), so batchTrigger requests carrying any per-item idempotencyKey failed. Rebuild the lookup as a plain parameterized string via $queryRawUnsafe (static SQL + integer placeholders, all values bound), so it no longer depends on which generated client executes it. Same per-key point-lookup shape; no change on the single-client path.
1 parent 80cbc46 commit 2967cdb

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Fix batchTrigger requests that set a per-item idempotency key failing with an error instead of creating and deduplicating the runs

internal-packages/run-store/src/PostgresRunStore.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface RunOpsCapableClient {
7272
// Standalone entity keyed by (environmentId, name); present on both schemas.
7373
waitpointTag: RunOpsDelegate<"upsert" | "findMany">;
7474
$queryRaw: PrismaClient["$queryRaw"];
75+
$queryRawUnsafe: PrismaClient["$queryRawUnsafe"];
7576
$executeRaw: PrismaClient["$executeRaw"];
7677
}
7778

@@ -1691,11 +1692,16 @@ export class PostgresRunStore implements RunStore {
16911692
return [];
16921693
}
16931694
const prisma = (client ?? this.readOnlyPrisma) as RunOpsCapableClient;
1694-
const branches = args.idempotencyKeys.map(
1695-
(key) =>
1696-
Prisma.sql`SELECT "friendlyId", "idempotencyKey", "idempotencyKeyExpiresAt" FROM "TaskRun" WHERE "runtimeEnvironmentId" = ${args.runtimeEnvironmentId} AND "taskIdentifier" = ${args.taskIdentifier} AND "idempotencyKey" = ${key}`
1695+
const params: string[] = [];
1696+
const branches = args.idempotencyKeys.map((key) => {
1697+
const base = params.length;
1698+
params.push(args.runtimeEnvironmentId, args.taskIdentifier, key);
1699+
return `SELECT "friendlyId", "idempotencyKey", "idempotencyKeyExpiresAt" FROM "TaskRun" WHERE "runtimeEnvironmentId" = $${base + 1} AND "taskIdentifier" = $${base + 2} AND "idempotencyKey" = $${base + 3}`;
1700+
});
1701+
return prisma.$queryRawUnsafe<IdempotencyKeyRunMatch[]>(
1702+
branches.join(" UNION ALL "),
1703+
...params
16971704
);
1698-
return prisma.$queryRaw<IdempotencyKeyRunMatch[]>(Prisma.join(branches, " UNION ALL "));
16991705
}
17001706

17011707
// --- run-ops persistence ---

0 commit comments

Comments
 (0)