From ffe29e5f7a9356c1e272e73ec9b6f47a4bb66073 Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Fri, 27 Mar 2026 15:55:41 +0000 Subject: [PATCH] fix: coerce empty-string parentFolderId to null in messageFolder toCore dual-write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sonarly.com/issue/19054?type=bug When a Microsoft-connected account syncs message folders, folders with no parent (parentFolderId = "") fail the core dual-write INSERT because the core schema expects a UUID column, not an empty string. Fix: In `toCore()`, the guard `if (parentFolderId && !uuidValidate(parentFolderId) && channelId)` correctly skips external-ID resolution when `parentFolderId` is falsy, but it leaves the original value (empty string `""`) in `coreData`. Since the core `messageFolder.parentFolderId` column is `uuid` type, PostgreSQL rejects the empty string. The fix adds an explicit `if (!parentFolderId)` branch that normalizes falsy values (empty string, null, undefined) to `null` before the data reaches TypeORM's INSERT. The existing external-ID resolution logic moves to an `else if` branch, preserving all current behavior for non-empty, non-UUID parentFolderIds. This handles all cases: - `""` (empty string from workspace save) → `null` ✓ - `null` / `undefined` → `null` ✓ - Valid UUID → passes through unchanged ✓ - Non-UUID external ID → resolved to core UUID via lookup ✓ --- .../services/message-folder-data-access.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/metadata-modules/message-folder/data-access/services/message-folder-data-access.service.ts b/packages/twenty-server/src/engine/metadata-modules/message-folder/data-access/services/message-folder-data-access.service.ts index 5937cbef604..38c13779022 100644 --- a/packages/twenty-server/src/engine/metadata-modules/message-folder/data-access/services/message-folder-data-access.service.ts +++ b/packages/twenty-server/src/engine/metadata-modules/message-folder/data-access/services/message-folder-data-access.service.ts @@ -44,7 +44,9 @@ export class MessageFolderDataAccessService { const parentFolderId = coreData.parentFolderId as string | null; const channelId = (coreData.messageChannelId as string) ?? messageChannelId; - if (parentFolderId && !uuidValidate(parentFolderId) && channelId) { + if (!parentFolderId) { + coreData.parentFolderId = null; + } else if (!uuidValidate(parentFolderId) && channelId) { const parentFolder = await this.coreRepository.findOne({ where: { workspaceId,