{"record":{"id":"7abe12332facb54f","repo":"twentyhq/twenty","slug":"failed-to-gate-export-import-command-menu-items-by","errorCode":null,"errorMessage":"Failed to gate export/import command menu items by permission flag for workspace ${workspaceId}","messagePattern":"Failed to gate export/import command menu items by permission flag for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-1/2-1-workspace-command-1790000000000-gate-export-import-command-menu-items-by-permission-flag.command.ts","lineNumber":132,"sourceCode":"          allFlatEntityOperationByMetadataName: {\n            commandMenuItem: {\n              flatEntityToCreate: [],\n              flatEntityToDelete: [],\n              flatEntityToUpdate: itemsToUpdate,\n            },\n          },\n          workspaceId,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n        },\n      );\n\n    if (validateAndBuildResult.status === 'fail') {\n      this.logger.error(\n        `Failed to update command menu item availability expressions:\\n${JSON.stringify(validateAndBuildResult, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to gate export/import command menu items by permission flag for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Successfully updated ${itemsToUpdate.length} command menu item availability expression(s) for workspace ${workspaceId}`,\n    );\n  }\n}\n","sourceCodeStart":114,"sourceCodeEnd":142,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-1/2-1-workspace-command-1790000000000-gate-export-import-command-menu-items-by-permission-flag.command.ts#L114-L142","documentation":"Thrown by the 2.1 workspace upgrade command when validateBuildAndRunLegacyWorkspaceMigration returns 'fail' while gating export/import command menu items behind a permission-flag availability expression. The command logs the failure JSON then throws to stop the workspace upgrade.","triggerScenarios":"Running the 2.1 permission-flag gating on a workspace whose export/import command menu items are missing from cache, or whose new availability expression the builder's expression validator rejects.","commonSituations":"Stale cache so the export/import items resolve to undefined; permission flag identifier referenced in the expression not registered in the build; partial prior run left items inconsistent.","solutions":["Read the logged validateAndBuildResult JSON for the exact expression or lookup error.","Recompute the workspace cache and retry.","Run --dryRun to confirm itemsToUpdate targets export/import items.","Verify the permission flag used in the expression exists in the installed build's permission definitions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Dry-run to preview expression changes, and confirm the permission flag referenced in the expression is registered:\nawait workspaceCacheService.invalidate(workspaceId);\nconst flagRegistered = await permissionFlagExists(workspaceId, EXPORT_IMPORT_PERMISSION_FLAG_ID);\nif (!flagRegistered) throw new Error('Permission flag not registered; cannot gate export/import items');","typeGuard":null,"tryCatchPattern":"try {\n  await command.runOnWorkspace({ workspaceId, options });\n} catch (err) {\n  logger.error(`Export/import gating failed for workspace ${workspaceId}`, err);\n  failedWorkspaces.push(workspaceId);\n}","preventionTips":["Run --dryRun to confirm itemsToUpdate targets export/import items.","Verify the permission flag used in the expression exists in the build's permission definitions.","Recompute the cache before running.","Catch per-workspace at the runner."],"tags":["migration","workspace-upgrade","command-menu-item","permissions","expression"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}