{"record":{"id":"c8f0f4129f1350cf","repo":"langflow-ai/langflow","slug":"invalid-target-folder","errorCode":null,"errorMessage":"Invalid target folder","messagePattern":"Invalid target folder","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/backend/base/langflow/agentic/utils/template_create.py","lineNumber":54,"sourceCode":"        session: Active async DB session.\n        user_id: The owner user id for the new flow.\n        template_id: The string id field inside the starter template JSON.\n        target_folder_id: Optional folder id to place the flow. If not provided,\n            the user's default folder will be used.\n\n    Returns:\n        Dict with keys: {\"id\": str, \"link\": str}\n    \"\"\"\n    # 1) Load template JSON from starter_projects\n    template = get_template_by_id(template_id=template_id, fields=None)\n    if not template:\n        raise HTTPException(status_code=404, detail=\"Template not found\")\n\n    # 2) Resolve target folder\n    if target_folder_id:\n        folder = await session.get(Folder, target_folder_id)\n        if not folder or folder.user_id != user_id:\n            raise HTTPException(status_code=400, detail=\"Invalid target folder\")\n        folder_id = folder.id\n    else:\n        default_folder = await get_or_create_default_folder(session, user_id)\n        folder_id = default_folder.id\n\n    # 3) Build FlowCreate from template fields (ignore unknowns)\n    new_flow = FlowCreate(\n        name=template.get(\"name\"),\n        description=template.get(\"description\"),\n        icon=template.get(\"icon\"),\n        icon_bg_color=template.get(\"icon_bg_color\"),\n        gradient=template.get(\"gradient\"),\n        data=template.get(\"data\"),\n        is_component=template.get(\"is_component\", False),\n        endpoint_name=template.get(\"endpoint_name\"),\n        tags=template.get(\"tags\"),\n        mcp_enabled=template.get(\"mcp_enabled\"),\n        folder_id=folder_id,","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/utils/template_create.py#L36-L72","documentation":"Raised when target_folder_id is supplied but the Folder row does not exist, or exists with a different user_id than the caller. Folder ownership is verified before placing the templated flow; unlike the flow lookup this returns 400 (bad request) rather than 404. Note the strict comparison folder.user_id != user_id — types must compare equal.","triggerScenarios":"Creating a flow from a template with target_folder_id set to a deleted folder, another user's folder, or a non-UUID value that fails session.get resolution.","commonSituations":"Folder deleted from another tab/client while its id was cached; team workspaces where a folder belongs to a colleague; stale folder ids persisted by an integration after re-login created new user records.","solutions":["Omit target_folder_id — the flow goes to your default folder automatically.","Or list your folders first (GET /api/v1/folders/) and pass an id you own from that response."],"exampleFix":"# before\ncreate_flow_from_template(template_id=tid, target_folder_id=\"<foreign id>\")\n\n# after\ncreate_flow_from_template(template_id=tid)  # defaults to caller's default folder","handlingStrategy":"validation","validationCode":"folders = (await client.get(\"/api/v1/folders/\")).json()\nowned = {f[\"id\"] for f in folders if f.get(\"user_id\") == my_user_id}\nif target_folder_id and target_folder_id not in owned:\n    target_folder_id = None  # fall back to default folder","typeGuard":null,"tryCatchPattern":"try:\n    create_flow_from_template(template_id=tid, target_folder_id=fid)\nexcept HTTPError as e:\n    if e.response.status_code == 400 and \"target folder\" in e.response.text:\n        create_flow_from_template(template_id=tid)  # default folder\n    else:\n        raise","preventionTips":["Omit target_folder_id unless you just fetched it from the folders API.","Re-fetch folder ids after login/user changes."],"tags":["folders","http-400","ownership","templates"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}