{"record":{"id":"252b291baf158cfc","repo":"langflow-ai/langflow","slug":"folder-not-found","errorCode":null,"errorMessage":"Folder not found","messagePattern":"Folder not found","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"src/backend/base/langflow/api/v1/flows_helpers.py","lineNumber":318,"sourceCode":"\n    Args:\n        session: Database session.\n        flow: Flow creation data.\n        user_id: Owner of the new flow.\n        storage_service: Service for filesystem operations.\n        flow_id: Allows PUT upsert to create flows with a specific ID for syncing between instances.\n        fail_on_endpoint_conflict: PUT should fail predictably on conflicts rather than silently renaming.\n        validate_folder: Validates folder_id exists and belongs to user when upserting from external sources.\n    \"\"\"\n    try:\n        await _verify_fs_path(flow.fs_path, user_id, storage_service)\n\n        if validate_folder and flow.folder_id is not None:\n            folder = (\n                await session.exec(select(Folder).where(Folder.id == flow.folder_id, Folder.user_id == user_id))\n            ).first()\n            if not folder:\n                raise HTTPException(status_code=400, detail=\"Folder not found\")\n\n        # Set user_id (ignore any user_id from body for security)\n        flow.user_id = user_id\n        flow.name = await _deduplicate_flow_name(session, flow.name, user_id)\n\n        if flow.endpoint_name:\n            flow.endpoint_name = await _deduplicate_endpoint_name(\n                session, flow.endpoint_name, user_id, fail_on_conflict=fail_on_endpoint_conflict\n            )\n\n        # Exclude the id field from FlowCreate so that Flow.id (UUID, non-optional)\n        # always gets its default_factory uuid4 unless we explicitly override it below.\n        db_flow = Flow.model_validate(flow.model_dump(exclude={\"id\"}))\n\n        # Apply the stable ID: explicit flow_id param (PUT upsert) takes precedence,\n        # then flow.id (stable import from FlowCreate), then the uuid4 default.\n        effective_id = flow_id if flow_id is not None else flow.id\n        if effective_id is not None:","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/flows_helpers.py#L300-L336","documentation":"HTTP 400 from _create_flow's upsert path: validate_folder was enabled (external-source/PUT upsert) and the submitted folder_id does not exist or does not belong to the acting user (query filters on both Folder.id and Folder.user_id). This stops external syncs from landing flows in another user's folder or a nonexistent one.","triggerScenarios":"PUT upsert with folder_id of a deleted folder, a folder owned by a different user, or a folder id copied from another instance/environment.","commonSituations":"Cross-instance sync where folder ids differ per instance; folder was deleted after the sync payload was built; client reuses ids from a staging environment against production.","solutions":["GET /api/v1/folders (as the same user) and use an id from that list.","Omit folder_id to let the flow land in the default folder.","Create the folder first when it is missing, then retry the upsert.","If syncing across instances, map folder names -> local ids instead of trusting foreign ids."],"exampleFix":"# before\n{\"name\":\"f\",\"folder_id\":\"<uuid-from-other-instance>\"}\n# after\nfolders = await client.get('/api/v1/folders')\nfolder = next(f for f in folders if f['name'] == 'Sync')\n{\"name\":\"f\",\"folder_id\":folder['id']}","handlingStrategy":"validation","validationCode":"const folders = await listFolders();\nif (body.folder_id && !folders.some(f => f.id === body.folder_id)) delete body.folder_id;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always resolve folder ids via GET /api/v1/folders for the current user","Map folder names to local ids in cross-instance syncs","Omit folder_id to use the default folder"],"tags":["validation","folders","http-400","upsert","flows"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}