Files
payload-automation/CRITICAL-CONFIG-FIX.md
Bas van den Aakster 08a4022a41 Add aggressive debugging logs to trace hook execution
- Add console.log statements that will ALWAYS appear if hooks are called
- Trace WorkflowExecutor creation and method availability
- Log every step of hook execution pipeline
- This will help identify exactly where the execution is failing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-01 20:47:38 +02:00

3.0 KiB

🚨 CRITICAL: Configuration Field Name Issue Found

The Root Problem

Your plugin configuration is using the wrong field name!

What You're Probably Using (WRONG):

automationPlugin({
  collections: ['orders', 'users', 'products'],  // ❌ Wrong field name
  steps: [...],
})

What You MUST Use (CORRECT):

automationPlugin({
  collectionTriggers: {     // ✅ Correct field name
    'orders': true,
    'users': true,
    'products': true
  },
  steps: [...],
})

🔧 Immediate Fix Required

Update your payload.config.ts file:

import { automationPlugin } from '@xtr-dev/payload-automation'

export default buildConfig({
  // ... your other config
  
  plugins: [
    automationPlugin({
      collectionTriggers: {    // ← CHANGE THIS FIELD NAME
        orders: true,          // Enable all hooks (create, read, update, delete)
        users: true,
        products: true
      },
      steps: [
        // ... your step configurations
      ]
    })
  ]
})

🎯 Why This Fixes Everything

  1. Hook Registration: The plugin only registers hooks for collections listed in collectionTriggers
  2. No Hooks = No Execution: If collectionTriggers is empty/missing, no hooks get registered
  3. Silent Failure: The plugin logs "No collection triggers configured" and returns early

🔍 Advanced Configuration Options

You can also be more specific about which operations trigger workflows:

automationPlugin({
  collectionTriggers: {
    orders: {
      update: true,    // Only trigger on updates
      create: true     // Only trigger on creates
      // read and delete are false by default
    },
    users: true        // Enable all operations
  },
  // ...
})

Expected Results After Fix

Once you update your configuration and restart:

  1. Plugin logs will show:

    Starting collection hook registration
    Collection hooks registered successfully - collectionSlug: "orders"
    
  2. Hook counts will be > 0:

    payload.collections.orders.config.hooks.afterChange.length
    // Should return a number > 0
    
  3. Workflow execution will work:

    • "AUTOMATION PLUGIN: Collection hook triggered" messages
    • Workflow runs created in database
    • Jobs processing successfully

🆘 If Still Not Working

If you fix the configuration and it still doesn't work:

  1. Check your exact collection slugs:

    console.log('Available collections:', Object.keys(payload.collections))
    
  2. Verify case sensitivity: Collection slugs are case-sensitive

    • Use exactly what appears in Object.keys(payload.collections)
  3. Restart completely:

    • Stop dev server
    • Clear any caches
    • Restart with new configuration

This configuration field name issue explains why no hooks were being registered, despite the plugin loading successfully. The v0.0.16 bug fix was valid, but this configuration issue was preventing hooks from being registered in the first place.