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
- Verify the workspace row: SELECT id, "workspaceCustomApplicationId" FROM core."workspace" WHERE id = $workspaceId
- If workspaceCustomApplicationId is null, check the application table for the workspace's custom application and update the column, or re-provision the workspace
- If the workspace is in a deleted/suspended state, exclude it from the upgrade iterator
- 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
- Verify workspace provisioning completed (custom application exists) before running upgrade commands
- Exclude workspaces in deleted/suspended states from the upgrade iterator
- Monitor provisioning for workspaces that fail to create the custom application
- Run a pre-upgrade check: SELECT count(*) FROM core."workspace" WHERE "workspaceCustomApplicationId" IS NULL
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
- Workspace custom application not found for workspace ${works
- Standard application is missing workflowVersion field coreWo
- Failed to add coreWorkflowVersionId field for workspace ${wo
- Standard application is missing workflow field coreWorkflowI
- Failed to add coreWorkflowId field for workspace ${workspace
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/dc03c75e94ded257.
Report an issue: GitHub.