{"record":{"id":"fddea007dfde0f57","repo":"twentyhq/twenty","slug":"workspace-custom-application-not-found-for-workspa-fddea0","errorCode":null,"errorMessage":"Workspace custom application not found for workspace ${workspaceId}","messagePattern":"Workspace custom application not found for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-23/2-23-workspace-command-1784286707000-backfill-workflow-core-links.command.ts","lineNumber":84,"sourceCode":"      this.logger.log(\n        `[DRY RUN] Would rebuild ${workspaceWorkflows.length} core workflow row(s) for workspace ${workspaceId}`,\n      );\n\n      return;\n    }\n\n    const queryRunner = dataSource.createQueryRunner();\n\n    await queryRunner.connect();\n\n    try {\n      const [workspace] = await queryRunner.query(\n        `SELECT \"databaseSchema\", \"workspaceCustomApplicationId\" FROM core.\"workspace\" WHERE id = $1`,\n        [workspaceId],\n      );\n\n      if (!isDefined(workspace?.workspaceCustomApplicationId)) {\n        throw new Error(\n          `Workspace custom application not found for workspace ${workspaceId}`,\n        );\n      }\n\n      const schema: string = workspace.databaseSchema;\n      const applicationId: string = workspace.workspaceCustomApplicationId;\n\n      await queryRunner.startTransaction();\n\n      try {\n        await queryRunner.query(\n          `DELETE FROM core.\"workflow\" WHERE \"workspaceId\" = $1`,\n          [workspaceId],\n        );\n\n        for (const workflow of workspaceWorkflows) {\n          const coreWorkflowId = uuidv4();\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-23/2-23-workspace-command-1784286707000-backfill-workflow-core-links.command.ts#L66-L102","documentation":"Thrown by the 2.23 command that rebuilds core workflow rows and links them via coreWorkflowId. The command opens a queryRunner, runs raw SQL to fetch databaseSchema and workspaceCustomApplicationId from core.workspace. If workspaceCustomApplicationId is null or the workspace row is absent, the command throws because it needs the application ID to INSERT core workflow rows.","triggerScenarios":"The workspaceId has no row in core.workspace, or the row's workspaceCustomApplicationId is null. Workspace provisioning never created the custom application, or it was removed.","commonSituations":"Incomplete workspace provisioning; workspace in a deleted/suspended state; manual DB modification; testing against a non-existent workspace ID.","solutions":["Verify the workspace row: SELECT id, \"workspaceCustomApplicationId\" FROM core.\"workspace\" WHERE id = $workspaceId","If workspaceCustomApplicationId is null, restore it from the application table or re-provision the workspace","Exclude deleted/suspended workspaces from the upgrade iterator","Check provisioning logs for the workspace"],"exampleFix":"// before: throws if workspaceCustomApplicationId is null\nif (!isDefined(workspace?.workspaceCustomApplicationId)) {\n  throw new Error(`Workspace custom application not found for workspace ${workspaceId}`);\n}\n\n// after: skip gracefully\nif (!isDefined(workspace?.workspaceCustomApplicationId)) {\n  this.logger.warn(`Workspace ${workspaceId} has no custom application, skipping core link backfill`);\n  return;\n}","handlingStrategy":"validation","validationCode":"// Before running the upgrade, verify the workspace has a custom application\nconst result = await dataSource.query(\n  `SELECT id, \"workspaceCustomApplicationId\" FROM core.\"workspace\" WHERE id = $1`,\n  [workspaceId],\n);\n\nif (!result[0] || !result[0].workspaceCustomApplicationId) {\n  console.error(`Workspace ${workspaceId} has no custom application — skip or re-provision`);\n}","typeGuard":"import { isDefined } from 'twenty-shared/utils';\n\nconst hasCustomApplication = (\n  workspace: { workspaceCustomApplicationId: string | null } | undefined,\n): workspace is { workspaceCustomApplicationId: string } =>\n  isDefined(workspace) && isDefined(workspace.workspaceCustomApplicationId);","tryCatchPattern":null,"preventionTips":["Verify workspace provisioning completed before running upgrade commands","Exclude workspaces in deleted/suspended states from the upgrade iterator","Run a pre-upgrade check for NULL workspaceCustomApplicationId values","Monitor workspace provisioning for failures"],"tags":["metadata","upgrade-command","workspace-data","data-integrity","workflow","raw-sql"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}