From af040b48a670046f05ac7dabba20768425a1e79c Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Fri, 13 Mar 2026 16:46:49 +0000 Subject: [PATCH] Missing messageChannel entity metadata during nested workspace context in error handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sonarly.com/issue/14490?type=bug Worker fails to mark a message channel as "failed" because the ORM entity metadata cache for the workspace doesn't include the `messageChannel` entity when loaded in a nested `executeInWorkspaceContext` call during error handling. Fix: **Fix: Align `findMetadata` with TypeORM's string target resolution** The `GlobalWorkspaceDataSource.findMetadata()` override used only strict reference equality (`metadata.target === target`) to match entity metadata. TypeORM's built-in `DataSource.getMetadata()` has additional fallback logic for string targets — it also checks `metadata.tableName` and `metadata.name`. The override was missing these fallbacks. When `target` is a string like `'messageChannel'` (as passed from `GlobalWorkspaceOrmManager.getRepository(workspaceId, 'messageChannel')`), and the cached `EntityMetadata.target` is set to the EntitySchema instance (not the string name), the strict `===` comparison fails. The fix adds the same fallback logic TypeORM uses: for string targets, also match against `metadata.tableName` and `metadata.name`. The existing `===` check is preserved as the first (fast-path) condition, so no existing behavior is broken. The string fallback only activates when the strict check fails. **File:** `packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.ts` --- .../global-workspace-datasource.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.ts b/packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.ts index 120bc501a4c..d623a600e40 100644 --- a/packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.ts +++ b/packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.ts @@ -85,7 +85,17 @@ export class GlobalWorkspaceDataSource extends DataSource { const context = getWorkspaceContext(); const { entityMetadatas } = context; - return entityMetadatas.find((metadata) => metadata.target === target); + return entityMetadatas.find((metadata) => { + if (metadata.target === target) { + return true; + } + + if (typeof target === 'string') { + return metadata.tableName === target || metadata.name === target; + } + + return false; + }); } override getMetadata(target: EntityTarget): EntityMetadata {