Skip to content

Commit 94eec6e

Browse files
authored
fix: handle fkey constraint violations in organization merge with llm (#3601)
1 parent 9e3a063 commit 94eec6e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

services/apps/merge_suggestions_worker/src/activities/organizationMergeSuggestions.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,22 @@ export async function removeOrganizationMergeSuggestions(
498498

499499
export async function addOrganizationSuggestionToNoMerge(suggestion: string[]): Promise<void> {
500500
if (suggestion.length !== 2) {
501-
svc.log.debug(`Suggestions array must have two ids!`)
501+
svc.log.debug('Suggestions array must have exactly two ids!')
502502
return
503503
}
504+
504505
const qx = pgpQx(svc.postgres.writer.connection())
505506

506-
await addOrgNoMerge(qx, suggestion[0], suggestion[1])
507+
try {
508+
await addOrgNoMerge(qx, suggestion[0], suggestion[1])
509+
} catch (error: unknown) {
510+
// Handle foreign key constraint violation gracefully
511+
if (error instanceof Error && 'code' in error && error.code === '23503') {
512+
svc.log.info({ suggestion }, 'Foreign key constraint violation, skipping no merge!')
513+
return
514+
}
515+
516+
svc.log.error({ error, suggestion }, 'Error adding organization suggestion to no merge!')
517+
throw error
518+
}
507519
}

0 commit comments

Comments
 (0)