{"record":{"id":"376eee5bfb9353fc","repo":"twentyhq/twenty","slug":"failed-to-remove-the-campaigns-navigation-menu-ite","errorCode":null,"errorMessage":"Failed to remove the Campaigns navigation menu item for workspace ${workspaceId}","messagePattern":"Failed to remove the Campaigns navigation menu item for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785332550000-remove-message-campaign-navigation-menu-item.command.ts","lineNumber":99,"sourceCode":"          workspaceId,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n          allFlatEntityOperationByMetadataName: {\n            navigationMenuItem: {\n              flatEntityToCreate: [],\n              flatEntityToDelete: navigationMenuItemsToDelete,\n              flatEntityToUpdate: [],\n            },\n          },\n        },\n      );\n\n    if (validateAndBuildResult.status === 'fail') {\n      this.logger.error(\n        `Failed to remove the Campaigns navigation menu item:\\n${JSON.stringify(validateAndBuildResult, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to remove the Campaigns navigation menu item for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Removed the Campaigns navigation menu item for workspace ${workspaceId}`,\n    );\n  }\n}\n","sourceCodeStart":81,"sourceCodeEnd":109,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785332550000-remove-message-campaign-navigation-menu-item.command.ts#L81-L109","documentation":"Thrown by the 2.25 command that removes the Campaigns navigation menu item from workspaces provisioned while it was built unconditionally. After collecting all navigationMenuItemsToDelete (filtered by the allMessageCampaigns universal identifier), the command calls validateBuildAndRunLegacyWorkspaceMigration with navigationMenuItem delete operations. If the pipeline fails, the result is logged to logger.error and the generic error is thrown.","triggerScenarios":"validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' when deleting navigationMenuItem flat entities. Caused by: the navigation menu item being referenced by other metadata (foreign key constraint), stale flatNavigationMenuItemMaps cache, or a DB error.","commonSituations":"The Campaigns navigation menu item is referenced by a view or page layout that wasn't cleaned up first; cache reports the item as present when it was already deleted; concurrent workspace modifications.","solutions":["Read the logger.error JSON output for the specific failure report","Flush flatNavigationMenuItemMaps from workspace cache and retry — the command is idempotent (skips if no items to delete)","Check for foreign key references to the navigation menu item in the workspace metadata","Run with --dryRun to inspect the planned deletions"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, flush navigation menu item cache\nawait workspaceCacheService.invalidateAndRecompute(workspaceId, [\n  'flatNavigationMenuItemMaps',\n]);\n\n// Confirm the Campaigns navigation menu item exists\nconst { flatNavigationMenuItemMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [\n  'flatNavigationMenuItemMaps',\n]);\n\nconst hasItem = Object.values(flatNavigationMenuItemMaps.byUniversalIdentifier)\n  .filter(isDefined)\n  .some((item) => item.universalIdentifier === ALL_MESSAGE_CAMPAIGNS_NAV_UID);\n\nif (!hasItem) {\n  console.log('Campaigns navigation menu item not present — command will skip');\n}","typeGuard":null,"tryCatchPattern":"// Retry once after flushing cache — the command is idempotent\ntry {\n  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n} catch (error) {\n  if (error.message.includes('Failed to remove the Campaigns navigation menu item')) {\n    await workspaceCacheService.flush(workspaceId, ['flatNavigationMenuItemMaps']);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Run with --dryRun first — the command skips if no items to delete","Flush flatNavigationMenuItemMaps cache before retrying","Parse the logger.error JSON for the specific navigationMenuItem validation failure","Check for foreign key references to the navigation menu item before retrying"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","navigation-menu-item","message-campaign"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}