⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(worker): skip an issue link that already exists during a Linear import (#635)
bercec04ab80498ad
diff --git a/apps/worker/src/__tests__/integration/import-store.test.ts b/apps/worker/src/__tests__/integration/import-store.test.tsindex 02c6e066..26f63942 100644--- a/apps/worker/src/__tests__/integration/import-store.test.ts+++ b/apps/worker/src/__tests__/integration/import-store.test.ts@@ -8,6 +8,7 @@ import {projectColumn,issue,issueAttachment,+ issueLink,importJob,user,getStorageSettings,@@ -28,6 +29,7 @@ import {createLocalStateAndRecord,createLocalIssueAndRecord,createLocalAttachmentAndRecord,+ createIssueLink,findImportRecord,retryImportJobLater,AttachmentRejectedError,@@ -297,6 +299,22 @@ describe('createLocalStateAndRecord', () => {});});+describe('createIssueLink', () => {+ it('drops the second insert of a pair that already exists', async () => {+ const { projectId, columnId } = await makeProject();+ const a = await makeIssue(projectId, columnId, 'A');+ const b = await makeIssue(projectId, columnId, 'B');++ // Linear returns a "related" relation from both issues, so Link sees the+ // pair once from each side.+ await createIssueLink(a, b, 'relates');+ await createIssueLink(b, a, 'relates');++ const rows = await db.select().from(issueLink).where(eq(issueLink.sourceIssueId, a));+ expect(rows).toHaveLength(1);+ });+});+describe('createLocalIssueAndRecord', () => {it('creates a new issue with a sequence number and records the mapping', async () => {const { projectId, columnId, userId } = await makeProject();diff --git a/apps/worker/src/import-store.ts b/apps/worker/src/import-store.tsindex 966a145f..e2004c6e 100644--- a/apps/worker/src/import-store.ts+++ b/apps/worker/src/import-store.ts@@ -717,8 +717,16 @@ export async function createIssueLink(}}+// drizzle wraps the driver error in a DrizzleQueryError and keeps the Postgres+// error in `cause`, so the code is looked for down the cause chain (the api's+// pgErrorCode does the same).function isUniqueViolation(err: unknown): boolean {- return typeof err === 'object' && err !== null && (err as { code?: string }).code === '23505';+ let current: unknown = err;+ for (let depth = 0; current && typeof current === 'object' && depth < 5; depth++) {+ if ((current as { code?: unknown }).code === '23505') return true;+ current = (current as { cause?: unknown }).cause;+ }+ return false;}// Only a user who already belongs to the project is matched: an import never