Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code ffe29e5f7a fix: coerce empty-string parentFolderId to null in messageFolder toCore dual-write
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 ✓
2026-03-27 15:55:41 +00:00
@@ -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,