From 8df9c854facb1c82fa6e4aae379f0b97293df87f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 13 Nov 2026 08:33:36 -0500 Subject: [PATCH] fix: Error imports that have nothing to import (#14577) An import with no input, or a Notion import with no shared pages, stayed in an active state with no tasks. This blocked new imports for the team until the creator canceled it. --- plugins/notion/server/index.ts | 2 +- server/queues/processors/ImportsProcessor.ts | 17 +++++++---- .../processors/JSONImportsProcessor.test.ts | 28 +++++++++++++++++++ server/routes/api/imports/schema.ts | 2 +- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 server/queues/processors/JSONImportsProcessor.test.ts diff --git a/plugins/notion/server/index.ts b/plugins/notion/server/index.ts index 7ad7cbe433..d79f645a7e 100644 --- a/plugins/notion/server/index.ts +++ b/plugins/notion/server/index.ts @@ -13,7 +13,7 @@ PluginManager.add({ type: Hook.ImportSchema, value: IntegrationImportBodySchema.extend({ service: z.literal(IntegrationService.Notion), - input: z.array(NotionImportInputItemSchema), + input: z.array(NotionImportInputItemSchema).min(1), }), }); diff --git a/server/queues/processors/ImportsProcessor.ts b/server/queues/processors/ImportsProcessor.ts index 99626cbb70..6f6bc4ba79 100644 --- a/server/queues/processors/ImportsProcessor.ts +++ b/server/queues/processors/ImportsProcessor.ts @@ -167,11 +167,20 @@ export default abstract class ImportsProcessor< * @returns Promise that resolves when the creation flow setup is done. */ private async onCreation(importModel: Import, transaction: Transaction) { - if (!importModel.input.length) { + const tasksInput = importModel.input.length + ? await this.buildTasksInput(importModel, transaction) + : []; + + // Without tasks nothing would move the import out of its current state. + if (!tasksInput.length) { + importModel.state = ImportState.Errored; + importModel.error = "Nothing to import"; + await importModel.saveWithCtx( + createContext({ user: importModel.createdBy, transaction }) + ); return; } - const tasksInput = await this.buildTasksInput(importModel, transaction); const phase = this.getInitialPhase(); const importTasks = await Promise.all( @@ -197,9 +206,7 @@ export default abstract class ImportsProcessor< importModel.state = ImportState.InProgress; await importModel.save({ transaction }); - if (importTasks.length > 0) { - await afterCommit(transaction, () => this.scheduleTask(importTasks[0])); - } + await afterCommit(transaction, () => this.scheduleTask(importTasks[0])); } /** diff --git a/server/queues/processors/JSONImportsProcessor.test.ts b/server/queues/processors/JSONImportsProcessor.test.ts new file mode 100644 index 0000000000..ace00200a2 --- /dev/null +++ b/server/queues/processors/JSONImportsProcessor.test.ts @@ -0,0 +1,28 @@ +import { ImportState, IntegrationService } from "@shared/types"; +import { ImportTask } from "@server/models"; +import { buildImport } from "@server/test/factories"; +import JSONImportsProcessor from "./JSONImportsProcessor"; + +describe("JSONImportsProcessor", () => { + it("should error an import with no input", async () => { + const importModel = await buildImport({ + service: IntegrationService.JSON, + input: [], + }); + + await new JSONImportsProcessor().perform({ + name: "imports.create", + modelId: importModel.id, + teamId: importModel.teamId, + actorId: importModel.createdById, + ip: "127.0.0.1", + }); + + await importModel.reload(); + expect(importModel.state).toEqual(ImportState.Errored); + expect(importModel.error).toEqual("Nothing to import"); + expect( + await ImportTask.count({ where: { importId: importModel.id } }) + ).toEqual(0); + }); +}); diff --git a/server/routes/api/imports/schema.ts b/server/routes/api/imports/schema.ts index dedd7fdf5b..cd3ef2a909 100644 --- a/server/routes/api/imports/schema.ts +++ b/server/routes/api/imports/schema.ts @@ -32,7 +32,7 @@ export const AttachmentImportBodySchema = z.object({ export const IntegrationImportBodySchema = z.object({ service: z.enum(ImportableIntegrationService), integrationId: z.uuid(), - input: z.array(BaseImportInputItemSchema), + input: z.array(BaseImportInputItemSchema).min(1), ...DestinationShape, });