twentyhq/twenty · error · Error

Failed to remove the Campaigns navigation menu item for work

Error message

Failed to remove the Campaigns navigation menu item for workspace ${workspaceId}

What it means

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.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785332550000-remove-message-campaign-navigation-menu-item.command.ts:99

          workspaceId,
          applicationUniversalIdentifier:
            twentyStandardFlatApplication.universalIdentifier,
          allFlatEntityOperationByMetadataName: {
            navigationMenuItem: {
              flatEntityToCreate: [],
              flatEntityToDelete: navigationMenuItemsToDelete,
              flatEntityToUpdate: [],
            },
          },
        },
      );

    if (validateAndBuildResult.status === 'fail') {
      this.logger.error(
        `Failed to remove the Campaigns navigation menu item:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
      );

      throw new Error(
        `Failed to remove the Campaigns navigation menu item for workspace ${workspaceId}`,
      );
    }

    this.logger.log(
      `Removed the Campaigns navigation menu item for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Read the logger.error JSON output for the specific failure report
  2. Flush flatNavigationMenuItemMaps from workspace cache and retry — the command is idempotent (skips if no items to delete)
  3. Check for foreign key references to the navigation menu item in the workspace metadata
  4. Run with --dryRun to inspect the planned deletions
Defensive patterns

Strategy: retry

Validate before calling

// Before running, flush navigation menu item cache
await workspaceCacheService.invalidateAndRecompute(workspaceId, [
  'flatNavigationMenuItemMaps',
]);

// Confirm the Campaigns navigation menu item exists
const { flatNavigationMenuItemMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [
  'flatNavigationMenuItemMaps',
]);

const hasItem = Object.values(flatNavigationMenuItemMaps.byUniversalIdentifier)
  .filter(isDefined)
  .some((item) => item.universalIdentifier === ALL_MESSAGE_CAMPAIGNS_NAV_UID);

if (!hasItem) {
  console.log('Campaigns navigation menu item not present — command will skip');
}

Try / catch

// Retry once after flushing cache — the command is idempotent
try {
  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
} catch (error) {
  if (error.message.includes('Failed to remove the Campaigns navigation menu item')) {
    await workspaceCacheService.flush(workspaceId, ['flatNavigationMenuItemMaps']);
    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/376eee5bfb9353fc. Report an issue: GitHub.