Missing messageChannel entity metadata during nested workspace context in error handler
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`
This commit is contained in:
+11
-1
@@ -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<ObjectLiteral>): EntityMetadata {
|
||||
|
||||
Reference in New Issue
Block a user