fix(issue-248): use unconditional empty settings object for cloud API compatibility

Issue #248 required three iterations to solve due to n8n API version differences:

1. First attempt: Whitelist filtering
   - Failed: API rejects ANY settings properties via update endpoint

2. Second attempt: Complete settings removal
   - Failed: Cloud API requires settings property to exist

3. Final solution: Unconditional empty settings object
   - Success: Satisfies both API requirements

Changes:
- src/services/n8n-validation.ts:153
  - Changed from conditional `if (cleanedWorkflow.settings)` to unconditional
  - Always sets `cleanedWorkflow.settings = {}`
  - Works for both cloud (requires property) and self-hosted (rejects properties)

- tests/unit/services/n8n-validation.test.ts
  - Updated all 4 tests to expect `settings: {}` instead of removed settings
  - Tests verify empty object approach works for all scenarios

Tested:
-  localhost workflow (wwTodXf1jbUy3Ja5)
-  cloud workflow (n8n.estyl.team/workflow/WKFeCRUjTeYbYhTf)
-  All 72 unit tests passing

References:
- https://community.n8n.io/t/api-workflow-update-endpoint-doesnt-support-setting-callerpolicy/161916
- Tested with @agent-n8n-mcp-tester on production workflows
This commit is contained in:
czlonkowski
2025-10-02 16:33:11 +02:00
parent fe1e3640af
commit 99518f71cf
5 changed files with 79 additions and 25 deletions

View File

@@ -134,17 +134,23 @@ export function cleanWorkflowForUpdate(workflow: Workflow): Partial<Workflow> {
} = workflow as any;
// CRITICAL FIX for Issue #248:
// The n8n API update endpoint has a strict schema that REJECTS settings updates.
// Properties like callerPolicy and executionOrder cannot be updated via the API
// (see: https://community.n8n.io/t/api-workflow-update-endpoint-doesnt-support-setting-callerpolicy/161916)
// The n8n API has version-specific behavior for settings in workflow updates:
//
// Solution: Remove settings entirely from update requests. The n8n API will
// preserve existing workflow settings when they are omitted from the update payload.
// This prevents "settings must NOT have additional properties" errors while
// ensuring workflow updates (name, nodes, connections) work correctly.
if (cleanedWorkflow.settings) {
delete cleanedWorkflow.settings;
}
// PROBLEM:
// - Some versions reject updates with settings properties (community forum reports)
// - Cloud versions REQUIRE settings property to be present (n8n.estyl.team)
// - Properties like callerPolicy and executionOrder cause "additional properties" errors
//
// SOLUTION:
// - ALWAYS set settings to empty object {}, regardless of whether it exists
// - Empty object satisfies "required property" validation (cloud API)
// - Empty object has no "additional properties" to trigger errors (self-hosted)
// - n8n API interprets empty settings as "no changes" and preserves existing settings
//
// References:
// - https://community.n8n.io/t/api-workflow-update-endpoint-doesnt-support-setting-callerpolicy/161916
// - Tested on n8n.estyl.team (cloud) and localhost (self-hosted)
cleanedWorkflow.settings = {};
return cleanedWorkflow;
}