Skip to content

Commit efbcebf

Browse files
fix(enrichment): cancel upsert dependents
1 parent e84015e commit efbcebf

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

apps/sim/lib/table/__tests__/update-row.test.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
421421
})
422422

423423
it('clears stale enrichment state when an upsert updates a matching row', async () => {
424+
const cancelSpy = vi.spyOn(workflowColumns, 'cancelWorkflowGroupRuns').mockResolvedValue()
424425
const runSpy = vi.spyOn(workflowColumns, 'runWorkflowColumn').mockResolvedValue()
425426
const enrichmentTable: TableDefinition = {
426427
...TABLE,
@@ -429,6 +430,7 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
429430
{ id: 'name', name: 'Name', type: 'string', unique: true },
430431
{ id: 'domain', name: 'Domain', type: 'string' },
431432
{ id: 'email', name: 'Email', type: 'string', workflowGroupId: 'group-1' },
433+
{ id: 'score', name: 'Score', type: 'number', workflowGroupId: 'group-2' },
432434
],
433435
workflowGroups: [
434436
{
@@ -440,6 +442,13 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
440442
inputMappings: [{ inputName: 'companyDomain', columnName: 'domain' }],
441443
outputs: [{ blockId: '', path: '', outputId: 'email', columnName: 'email' }],
442444
},
445+
{
446+
id: 'group-2',
447+
workflowId: 'workflow-2',
448+
autoRun: true,
449+
dependencies: { columns: ['email'] },
450+
outputs: [{ blockId: 'block-2', path: 'score', columnName: 'score' }],
451+
},
443452
],
444453
},
445454
}
@@ -449,7 +458,7 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
449458
dbChainMockFns.limit.mockResolvedValueOnce([
450459
{
451460
...EXISTING_ROW,
452-
data: { name: 'Alice', domain: 'old.example', email: 'person@old.example' },
461+
data: { name: 'Alice', domain: 'old.example', email: 'person@old.example', score: 10 },
453462
},
454463
])
455464
queueTableRows(tableRowExecutions, [
@@ -466,6 +475,19 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
466475
blockErrors: {},
467476
cancelledAt: null,
468477
},
478+
{
479+
rowId: 'row-1',
480+
groupId: 'group-2',
481+
status: 'running',
482+
executionId: 'execution-2',
483+
jobId: 'job-2',
484+
workflowId: 'workflow-2',
485+
isManualRun: false,
486+
error: null,
487+
runningBlockIds: [],
488+
blockErrors: {},
489+
cancelledAt: null,
490+
},
469491
])
470492
dbChainMockFns.returning.mockResolvedValueOnce([
471493
{
@@ -486,8 +508,15 @@ describe('insertRow — position race safety (migration 0198 + advisory lock)',
486508
)
487509

488510
expect(result.row.data).toEqual({ name: 'Alice', domain: 'new.example', email: null })
489-
expect(result.row.executions).toEqual({})
511+
expect(result.row.executions['group-1']).toBeUndefined()
490512
expect(dbChainMockFns.delete).toHaveBeenCalledWith(tableRowExecutions)
513+
await vi.waitFor(() => {
514+
expect(cancelSpy).toHaveBeenCalledWith('tbl-1', 'row-1', { groupIds: ['group-2'] })
515+
expect(runSpy).toHaveBeenCalledWith(
516+
expect.objectContaining({ groupIds: ['group-2'], isManualRun: true })
517+
)
518+
})
519+
cancelSpy.mockRestore()
491520
runSpy.mockRestore()
492521
})
493522
})

apps/sim/lib/table/rows/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ export async function upsertRow(
740740
if (!previousData) throw new Error('Matched table row is missing data')
741741
const existingExecutions = await loadExecutionsForRow(trx, matchedRowId)
742742
const existingState = { data: previousData, executions: existingExecutions }
743-
const dataBeforeDerivedClears = { ...data.data }
743+
const dataBeforeDerivedClears = { ...previousData, ...data.data }
744744
const persistedData: RowData = {
745745
...data.data,
746746
...getInvalidatedManualEnrichmentOutputClears(

0 commit comments

Comments
 (0)