fix: handle empty settings in workflow creation and update comments

Fixed two additional issues discovered in CI testing:

1. cleanWorkflowForCreate() now treats empty settings {} the same as
   missing settings - adds default settings in both cases

2. Updated outdated comments referencing old approach of using empty
   objects for safety

Root Cause:
- Tests were creating workflows with settings: {}
- Empty object {} is truthy in JavaScript, so the check !settings
  passed and no defaults were added
- This caused workflows to be created without proper settings
- Later autofix updates would then fail

Changes:
- Modified cleanWorkflowForCreate() line 107 to check both !settings
  and Object.keys(settings).length === 0
- Updated comment lines 157-172 to reflect current approach
- Now empty settings objects are handled consistently

Testing:
- All 75 unit tests in n8n-validation.test.ts passing
- Fixes CI integration test failures in autofix-workflow.test.ts

Related: #431

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

Co-Authored-By: Claude <noreply@anthropic.com>

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en
This commit is contained in:
czlonkowski
2025-11-20 16:47:54 +01:00
parent d8a08947fa
commit f54d8b6caa

View File

@@ -103,7 +103,8 @@ export function cleanWorkflowForCreate(workflow: Partial<Workflow>): Partial<Wor
} = workflow;
// Ensure settings are present with defaults
if (!cleanedWorkflow.settings) {
// Treat empty settings object {} the same as missing settings
if (!cleanedWorkflow.settings || Object.keys(cleanedWorkflow.settings).length === 0) {
cleanedWorkflow.settings = defaultWorkflowSettings;
}
@@ -155,16 +156,17 @@ export function cleanWorkflowForUpdate(workflow: Workflow): Partial<Workflow> {
//
// 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 cause "additional properties" errors
// - Empty settings objects {} cause "additional properties" validation errors (Issue #431)
//
// SOLUTION:
// - Filter settings to only include whitelisted properties (OpenAPI spec)
// - If no settings provided, use empty object {} for safety
// - Empty object satisfies "required property" validation (cloud API)
// - If no settings after filtering, omit the property entirely (n8n API rejects empty objects)
// - Omitting the property prevents "additional properties" validation errors
// - Whitelisted properties prevent "additional properties" errors
//
// References:
// - Issue #431: Empty settings validation error
// - https://community.n8n.io/t/api-workflow-update-endpoint-doesnt-support-setting-callerpolicy/161916
// - OpenAPI spec: workflowSettings schema
// - Tested on n8n.estyl.team (cloud) and localhost (self-hosted)