twentyhq/twenty · critical · Error

Workspace custom application not found for workspace ${works

Error message

Workspace custom application not found for workspace ${workspaceId}

What it means

Thrown by the 2.22 command that rebuilds core workflowVersion rows and links them via coreWorkflowVersionId. The command opens a queryRunner, runs raw SQL to fetch the workspace's databaseSchema and workspaceCustomApplicationId from core.workspace. If workspaceCustomApplicationId is null or the workspace row does not exist, the command throws because it needs the application ID to INSERT core workflowVersion rows with the correct applicationId foreign key.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1784193207000-backfill-workflow-version-core-links.command.ts:87

      this.logger.log(
        `[DRY RUN] Would rebuild ${workspaceWorkflowVersions.length} core workflowVersion row(s) for workspace ${workspaceId}`,
      );

      return;
    }

    const queryRunner = dataSource.createQueryRunner();

    await queryRunner.connect();

    try {
      const [workspace] = await queryRunner.query(
        `SELECT "databaseSchema", "workspaceCustomApplicationId" FROM core."workspace" WHERE id = $1`,
        [workspaceId],
      );

      if (!isDefined(workspace?.workspaceCustomApplicationId)) {
        throw new Error(
          `Workspace custom application not found for workspace ${workspaceId}`,
        );
      }

      const schema: string = workspace.databaseSchema;
      const applicationId: string = workspace.workspaceCustomApplicationId;

      await queryRunner.startTransaction();

      try {
        await queryRunner.query(
          `DELETE FROM core."workflowVersion" WHERE "workspaceId" = $1`,
          [workspaceId],
        );

        for (const workflowVersion of workspaceWorkflowVersions) {
          const coreWorkflowVersionId = uuidv4();

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Verify the workspace row: SELECT id, "workspaceCustomApplicationId" FROM core."workspace" WHERE id = $workspaceId
  2. If workspaceCustomApplicationId is null, check the application table for the workspace's custom application and update the column, or re-provision the workspace
  3. If the workspace is in a deleted/suspended state, exclude it from the upgrade iterator
  4. Check workspace provisioning logs for errors during custom application creation

Example fix

// before: throws if workspaceCustomApplicationId is null
if (!isDefined(workspace?.workspaceCustomApplicationId)) {
  throw new Error(`Workspace custom application not found for workspace ${workspaceId}`);
}

// after: skip with a warning instead of crashing the upgrade
if (!isDefined(workspace?.workspaceCustomApplicationId)) {
  this.logger.warn(`Workspace ${workspaceId} has no custom application, skipping core link backfill`);
  return;
}
Defensive patterns

Strategy: validation

Validate before calling

// Before running the upgrade, verify the workspace has a custom application
const result = await dataSource.query(
  `SELECT id, "workspaceCustomApplicationId" FROM core."workspace" WHERE id = $1`,
  [workspaceId],
);

if (!result[0] || !result[0].workspaceCustomApplicationId) {
  console.error(`Workspace ${workspaceId} has no custom application — skip or re-provision`);
  // Do not run this command for this workspace
}

Type guard

import { isDefined } from 'twenty-shared/utils';

interface WorkspaceRow {
  databaseSchema: string;
  workspaceCustomApplicationId: string | null;
}

const hasCustomApplication = (
  workspace: WorkspaceRow | undefined,
): workspace is WorkspaceRow & { workspaceCustomApplicationId: string } =>
  isDefined(workspace) && isDefined(workspace.workspaceCustomApplicationId);

Prevention

When it happens

Trigger: The workspaceId passed to runOnWorkspace has no row in core.workspace, or the row exists but workspaceCustomApplicationId is null. This means workspace provisioning never created (or deleted) the custom application record.

Common situations: Workspace provisioning failed partway through (workspace row created, custom application not); the workspace was soft-deleted or is in a cleanup state; a manual DB operation nullified the column; testing against a workspace ID that doesn't exist.

Related errors


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