{"record":{"id":"321097cdfc763590","repo":"twentyhq/twenty","slug":"failed-to-add-send-email-record-selection-commands","errorCode":null,"errorMessage":"Failed to add Send Email record-selection commands for workspace ${workspaceId}","messagePattern":"Failed to add Send Email record-selection commands for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/1-22/1-22-workspace-command-1775500016000-add-send-email-record-selection-command-menu-items.command.ts","lineNumber":126,"sourceCode":"          allFlatEntityOperationByMetadataName: {\n            commandMenuItem: {\n              flatEntityToCreate: itemsToCreate,\n              flatEntityToDelete: [],\n              flatEntityToUpdate: [],\n            },\n          },\n          workspaceId,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n        },\n      );\n\n    if (validateAndBuildResult.status === 'fail') {\n      this.logger.error(\n        `Failed to add Send Email record-selection commands:\\n${JSON.stringify(validateAndBuildResult, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to add Send Email record-selection commands for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Successfully added ${itemsToCreate.length} Send Email record-selection commands for workspace ${workspaceId}`,\n    );\n  }\n}\n","sourceCodeStart":108,"sourceCodeEnd":136,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/1-22/1-22-workspace-command-1775500016000-add-send-email-record-selection-command-menu-items.command.ts#L108-L136","documentation":"Thrown by the 1.22 workspace upgrade command when validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' during creation of the new 'Send Email' record-selection command menu items. The detailed failure payload is logged before the throw so the operator can see why the build rejected the create operations.","triggerScenarios":"Running the 1.22 Send Email record-selection command-menu-item creation on a workspace where the referenced parent command or object metadata is absent, or where the new items duplicate existing universal identifiers / keys the validator forbids.","commonSituations":"Workspace cache lacks the Send Email command the items attach to; a previous run partially created the items leaving duplicates; standard application flat-entity maps out of sync with the workspace's stored application.","solutions":["Inspect the logged validateAndBuildResult JSON for the specific create rejection (duplicate identifier, missing parent, etc.).","Recompute the workspace cache and re-run so the existing-items diff is accurate.","Run --dryRun first to see the planned itemsToCreate.","Scope the upgrade to the failing workspace and resolve the flagged metadata before continuing the fleet."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Dry-run to preview itemsToCreate, and confirm the parent Send Email command exists:\nawait workspaceCacheService.invalidate(workspaceId);\nconst { flatCommandMenuItemMaps } = await workspaceCacheService.getOrRecompute(workspaceId, ['flatCommandMenuItemMaps']);\nconst parentExists = isDefined(flatCommandMenuItemMaps.byUniversalIdentifier[SEND_EMAIL_COMMAND_ID]);\nif (!parentExists) throw new Error('Parent Send Email command missing; cannot attach record-selection items');","typeGuard":null,"tryCatchPattern":"try {\n  await command.runOnWorkspace({ workspaceId, options });\n} catch (err) {\n  logger.error(`Send Email item creation failed for workspace ${workspaceId}`, err);\n  failedWorkspaces.push(workspaceId);\n}","preventionTips":["Run --dryRun to verify itemsToCreate before committing.","Ensure the parent command the new items attach to exists in the workspace cache.","Recompute the cache before running; stale caches cause phantom missing-parent failures.","Catch per-workspace at the runner to keep the fleet moving."],"tags":["migration","workspace-upgrade","command-menu-item","send-email"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}