Skip to content

Commit e0292fc

Browse files
fix(idempotency): use compatible PostgreSQL JSON operations (#6510)
1 parent 328d985 commit e0292fc

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

apps/sim/lib/core/idempotency/service.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ describe('IdempotencyService in-progress deadlines', () => {
154154

155155
const conflictOptions = dbChainMockFns.onConflictDoUpdate.mock.calls[0]?.[0]
156156
const setWhere = JSON.stringify(conflictOptions?.setWhere)
157+
expect(setWhere).toContain('json_typeof')
158+
expect(setWhere).not.toContain('jsonb_typeof')
157159
expect(setWhere).toContain('IS DISTINCT FROM')
158160
expect(setWhere).toContain('in-progress')
159161
})
@@ -229,7 +231,8 @@ describe('IdempotencyService in-progress deadlines', () => {
229231
service.executeWithIdempotency('provider', 'delivery-retry-db', vi.fn())
230232
).resolves.toBe('new-owner-result')
231233

232-
const condition = dbChainMockFns.where.mock.calls.at(-1)?.[0]
233-
expect(JSON.stringify(condition)).toContain('retry me')
234+
const condition = JSON.stringify(dbChainMockFns.where.mock.calls.at(-1)?.[0])
235+
expect(condition).toContain('retry me')
236+
expect(condition.match(/::jsonb/g)).toHaveLength(2)
234237
})
235238
})

apps/sim/lib/core/idempotency/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export class IdempotencyService {
327327
const expiredBefore = new Date(now.getTime() - this.config.ttlSeconds * 1000)
328328
const inProgressClaimExpired = sql`COALESCE(
329329
CASE
330-
WHEN jsonb_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
330+
WHEN json_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
331331
THEN (${idempotencyKey.result} ->> 'inProgressExpiresAt')::double precision
332332
END,
333333
EXTRACT(EPOCH FROM ${idempotencyKey.createdAt}) * 1000 + ${this.config.inProgressTtlSeconds * 1000}
@@ -548,7 +548,7 @@ export class IdempotencyService {
548548
: fence?.observedResult
549549
? and(
550550
eq(idempotencyKey.key, normalizedKey),
551-
sql`${idempotencyKey.result} = ${JSON.stringify(fence.observedResult)}::jsonb`
551+
sql`${idempotencyKey.result}::jsonb = ${JSON.stringify(fence.observedResult)}::jsonb`
552552
)
553553
: eq(idempotencyKey.key, normalizedKey)
554554
const deleted = await db

0 commit comments

Comments
 (0)