From 3d7b7467793e05cdf6f9845971fdbc5b94b67bf7 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Mon, 1 Sep 2025 10:32:51 +0200 Subject: [PATCH] Fix workflow trigger field name mismatch - Update workflow executor to check both 'collection' and 'collectionSlug' fields - Add debug logging for workflow trigger matching - Fixes issue where collection triggers were not being matched correctly --- src/core/workflow-executor.ts | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/workflow-executor.ts b/src/core/workflow-executor.ts index 787af81..c77375a 100644 --- a/src/core/workflow-executor.ts +++ b/src/core/workflow-executor.ts @@ -606,6 +606,12 @@ export class WorkflowExecutor { previousDoc: unknown, req: PayloadRequest ): Promise { + this.logger.info({ + collection, + operation, + docId: (doc as any)?.id + }, 'executeTriggeredWorkflows called') + try { // Find workflows with matching triggers const workflows = await this.payload.find({ @@ -614,21 +620,46 @@ export class WorkflowExecutor { limit: 100, req }) + + this.logger.info({ + workflowCount: workflows.docs.length + }, 'Found workflows to check') for (const workflow of workflows.docs) { // Check if this workflow has a matching trigger const triggers = workflow.triggers as Array<{ - collection: string + collection?: string + collectionSlug?: string condition?: string operation: string type: string }> + + this.logger.debug({ + workflowId: workflow.id, + workflowName: workflow.name, + triggerCount: triggers?.length || 0, + triggers: triggers?.map(t => ({ + type: t.type, + collection: t.collection, + collectionSlug: t.collectionSlug, + operation: t.operation + })) + }, 'Checking workflow triggers') const matchingTriggers = triggers?.filter(trigger => trigger.type === 'collection-trigger' && - trigger.collection === collection && + (trigger.collection === collection || trigger.collectionSlug === collection) && trigger.operation === operation ) || [] + + this.logger.info({ + workflowId: workflow.id, + workflowName: workflow.name, + matchingTriggerCount: matchingTriggers.length, + targetCollection: collection, + targetOperation: operation + }, 'Matching triggers found') for (const trigger of matchingTriggers) { // Create execution context for condition evaluation