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.
This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-13 08:33:36 -05:00
1 parent 6fd7eb7cf0
commit 8df9c854fa
4 files changed
+42 -7

No files matched your search

+1 -1
View File
@@ -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),
}),
});
+12 -5
View File
@@ -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<T>, 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]));
}
/**
@@ -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);
});
});
+1 -1
View File
@@ -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,
});