From 5000affc261af7b800d5e2adc0e62fbbfbafe958 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 18 Feb 2021 12:15:09 +0800 Subject: [PATCH] fix: skip non-existent collection --- packages/plugin-automations/src/models/automation-job.ts | 3 +++ packages/plugin-automations/src/models/automation.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/plugin-automations/src/models/automation-job.ts b/packages/plugin-automations/src/models/automation-job.ts index ab1934af8..bca105afd 100644 --- a/packages/plugin-automations/src/models/automation-job.ts +++ b/packages/plugin-automations/src/models/automation-job.ts @@ -54,6 +54,9 @@ export class AutomationJobModel extends Model { const jobType = this.get('type'); const collectionName = this.get('collection_name'); const M = this.database.getModel(collectionName); + if (!collectionName || !M) { + return; + } let filter: any = this.toFilter(result); let data: any = this.toValues(result); const { where = {} } = M.parseApiJson({ filter }); diff --git a/packages/plugin-automations/src/models/automation.ts b/packages/plugin-automations/src/models/automation.ts index 8fc84ef88..72d3e8003 100644 --- a/packages/plugin-automations/src/models/automation.ts +++ b/packages/plugin-automations/src/models/automation.ts @@ -82,6 +82,9 @@ export class AutomationModel extends Model { const changedFields = (this.get('changed') as any) || []; const M = this.database.getModel(collectionName); const automationType = this.get('type'); + if (automationType !== 'schedule' || !collectionName || !M) { + return; + } switch (automationType) { case 'collections:afterCreate': M.addHook('afterCreate', hookName, async (model, options) => {