{"record":{"id":"e7ed0d4a576c7ce9","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-deletechatflow-worksp","errorCode":null,"errorMessage":"Error: chatflowsController.deleteChatflow - workspace ${workspaceId} not found!","messagePattern":"Error: chatflowsController\\.deleteChatflow - workspace (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":64,"sourceCode":"        next(error)\n    }\n}\n\nconst deleteChatflow = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.deleteChatflow - id not provided!`)\n        }\n        const orgId = req.user?.activeOrganizationId\n        if (!orgId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.deleteChatflow - organization ${orgId} not found!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.deleteChatflow - workspace ${workspaceId} not found!`\n            )\n        }\n        const userPermittedTypes: EnumChatflowType[] = []\n        const permissions = req.user!.permissions\n        if (req.user?.isOrganizationAdmin) {\n            userPermittedTypes.push(EnumChatflowType.CHATFLOW)\n            userPermittedTypes.push(EnumChatflowType.AGENTFLOW)\n            userPermittedTypes.push(EnumChatflowType.MULTIAGENT)\n            userPermittedTypes.push(EnumChatflowType.ASSISTANT)\n        } else {\n            if (permissions.includes(`chatflows:delete`)) userPermittedTypes.push(EnumChatflowType.CHATFLOW)\n            if (permissions.includes(`agentflows:delete`)) userPermittedTypes.push(EnumChatflowType.AGENTFLOW)\n            if (permissions.includes(`agentflows:delete`)) userPermittedTypes.push(EnumChatflowType.MULTIAGENT)\n            if (permissions.includes(`assistants:delete`)) userPermittedTypes.push(EnumChatflowType.ASSISTANT)\n            if (userPermittedTypes.length === 0)\n                throw new InternalFlowiseError(StatusCodes.FORBIDDEN, `You do not have permission to delete any chatflow types`)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L46-L82","documentation":"Thrown by deleteChatflow when req.user?.activeWorkspaceId is absent (after org check passed). Returns 404 NOT_FOUND — again misleading, as the user context is incomplete rather than a record missing. Indicates the session has an org but no workspace selected/assigned.","triggerScenarios":"Authenticated DELETE with a token containing activeOrganizationId but no activeWorkspaceId. Happens when a user is in an org but hasn't selected or been assigned a workspace.","commonSituations":"Org admin created the user but no workspace was assigned; workspace_user row missing; client skipped the workspace-selection step after login; token minted before workspace feature shipped.","solutions":["Confirm the user has a workspace membership row (workspace_user table).","Run the workspace selection/switch flow so the active workspace claim is set.","Check auth middleware injects activeWorkspaceId on this route.","Decode JWT and verify the workspace claim exists."],"exampleFix":"// before: logged in but no workspace selected\n// after: select a workspace to populate the claim\nawait api.post('/workspaces/select', { workspaceId })\nawait api.delete(`/api/v1/chatflows/${id}`)","handlingStrategy":"validation","validationCode":"function hasWorkspaceClaim(user): boolean {\n  return Boolean(user && (user as any).activeWorkspaceId)\n}\nif (!hasWorkspaceClaim(currentUser)) {\n  // run workspace selection before delete\n}","typeGuard":"function hasWorkspaceContext(u: unknown): u is { activeWorkspaceId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeWorkspaceId === 'string' && (u as any).activeWorkspaceId.length > 0\n}","tryCatchPattern":null,"preventionTips":["Run the workspace selection step in the login flow.","Ensure every user has a workspace_user row at provisioning.","Verify the workspace-injecting middleware is on the delete route.","Decode the JWT to confirm the workspace claim."],"tags":["flowise","express","auth","workspace","multitenant","controller"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}