{"record":{"id":"c2b59843d093df90","repo":"langgenius/dify","slug":"invalid-filters","errorCode":null,"errorMessage":"Invalid filters","messagePattern":"Invalid filters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/app/workflow.py","lineNumber":1390,"sourceCode":"    @console_ns.doc(params=query_params_from_model(DefaultBlockConfigQuery))\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_VIEW_LAYOUT)\n    @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])\n    def get(self, app_model: App, block_type: str):\n        \"\"\"\n        Get default block config\n        \"\"\"\n        args = DefaultBlockConfigQuery.model_validate(request.args.to_dict(flat=True))\n\n        filters = None\n        if args.q:\n            try:\n                filters = json.loads(args.q)\n            except json.JSONDecodeError:\n                raise ValueError(\"Invalid filters\")\n\n        # Get default block configs\n        workflow_service = WorkflowService()\n        return workflow_service.get_default_block_config(node_type=block_type, filters=filters)\n\n\n@console_ns.route(\"/apps/<uuid:app_id>/convert-to-workflow\")\nclass ConvertToWorkflowApi(Resource):\n    @console_ns.expect(console_ns.models[ConvertToWorkflowPayload.__name__])\n    @console_ns.doc(\"convert_to_workflow\")\n    @console_ns.doc(description=\"Convert application to workflow mode\")\n    @console_ns.doc(params={\"app_id\": \"Application ID\"})\n    @console_ns.response(\n        200,\n        \"Application converted to workflow successfully\",\n        console_ns.models[NewAppResponse.__name__],\n    )\n    @console_ns.response(400, \"Application cannot be converted\")","sourceCodeStart":1372,"sourceCodeEnd":1408,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L1372-L1408","documentation":"Bare ValueError('Invalid filters') raised inside DefaultBlockConfigApi.get (GET /apps/{app_id}/workflows/default-workflow-block-configs/{block_type}) when the 'q' query string is present but fails json.loads (json.JSONDecodeError). The value is forwarded as filters to WorkflowService.get_default_block_config. The ValueError propagates as HTTP 400 'Invalid filters'.","triggerScenarios":"Passing a malformed 'q' parameter that is not valid JSON, e.g. ?q=foo or ?q={bad, on the default-block-config endpoint.","commonSituations":"Frontend builds the q param by string concatenation instead of JSON.stringify; copy-pasted URL with truncated JSON; manual API testing with unencoded braces.","solutions":["URL-encode a JSON.stringify-ed object for the q parameter, or omit it entirely.","Validate that q parses as JSON on the client before sending.","If no filter is needed, drop the q query parameter."],"exampleFix":"// before: raw, un-encoded JSON in the URL\nfetch(`/apps/${appId}/workflows/default-workflow-block-configs/llm?q={provider:openai}`)\n// after: JSON.stringify + encodeURIComponent\nconst q = encodeURIComponent(JSON.stringify({provider:'openai'}));\nfetch(`/apps/${appId}/workflows/default-workflow-block-configs/llm?q=${q}`)","handlingStrategy":"validation","validationCode":"// Validate q parses as JSON before sending; drop it if it doesn't.\nlet q;\ntry { q = rawQ ? JSON.parse(rawQ) : undefined; } catch { q = undefined; /* or show client error */ }\nconst url = `/console/apps/${appId}/workflows/default-workflow-block-configs/${blockType}` +\n  (q ? `?q=${encodeURIComponent(JSON.stringify(q))}` : '');","typeGuard":"const isJsonString = (s): boolean => { try { JSON.parse(s); return true; } catch { return false; } };","tryCatchPattern":"try {\n  return await getDefaultBlockConfig(appId, blockType, q);\n} catch (e) {\n  if (e?.status === 400 && /Invalid filters/i.test(e?.message)) {\n    // drop q and retry without filters\n    return getDefaultBlockConfig(appId, blockType, undefined);\n  }\n  throw e;\n}","preventionTips":["Always build the q parameter with JSON.stringify + encodeURIComponent.","Omit q entirely when no filter is needed.","Add a client-side JSON validity check before issuing the request."],"tags":["validation","filters","block-config","workflow","console-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}