{"record":{"id":"5ad1768057ebcac2","repo":"langgenius/dify","slug":"missing-dataset-id-or-pipeline-id-in-request-path","errorCode":null,"errorMessage":"Missing dataset_id or pipeline_id in request path","messagePattern":"Missing dataset_id or pipeline_id in request path","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/common/wraps.py","lineNumber":178,"sourceCode":"            return authz_app_id or str(agent_id)\n\n        resource_id = matched_args.get(\"resource_id\")\n        if resource_id:\n            return str(resource_id)  # pyrefly: ignore[unnecessary-type-conversion]\n        raise ValueError(\"Missing app_id in request path\")\n\n    if resource_type == RBACResourceScope.DATASET:\n        dataset_id = matched_args.get(\"dataset_id\") or matched_args.get(\"resource_id\")\n        if dataset_id:\n            return str(dataset_id)\n\n        pipeline_id = matched_args.get(\"pipeline_id\")\n        if pipeline_id:\n            dataset = db.session.scalar(select(Dataset).where(Dataset.pipeline_id == str(pipeline_id)))\n            if not dataset:\n                raise NotFound(\"Dataset not found for pipeline\")\n            return str(dataset.id)  # pyrefly: ignore[unnecessary-type-conversion]\n        raise ValueError(\"Missing dataset_id or pipeline_id in request path\")\n    raise ValueError(f\"Unknown resource_type: {resource_type}\")\n","sourceCodeStart":160,"sourceCodeEnd":180,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/common/wraps.py#L160-L180","documentation":"A ValueError raised inside _extract_resource_id when a route is declared RBAC-scoped to DATASET but the matched path args contain neither dataset_id (nor legacy resource_id) nor pipeline_id. It is a programming/routing error rather than a client error: the route is wired to RBAC dataset authz but its URL pattern does not supply the identifiers the extractor expects.","triggerScenarios":"Adding @rbac_permission_required(RBACResourceScope.DATASET, ...) to a new route whose URL pattern uses a different parameter name (e.g. <library_id> or <collection_id>); deploying a dataset-scoped route without <dataset_id>/<resource_id>/<pipeline_id> in its path. Surfaces as a 500 on first request to that route.","commonSituations":"New dataset sub-resource endpoint wired with the wrong path parameter name; refactor that renamed a path arg without updating _extract_resource_id's recognized names; copy-paste of an RBAC decorator onto a route that is not actually dataset-addressed.","solutions":["Ensure the route URL contains one of dataset_id, resource_id, or pipeline_id as a path converter (e.g. /console/datasets/<uuid:dataset_id>/items).","If the route legitimately needs a different param name, extend _extract_resource_id's matched_args lookup to recognize it.","Remove RBACResourceScope.DATASET from the decorator if the route is not dataset-scoped.","Add a unit test over _extract_resource_id for the new route's path args to prevent regression."],"exampleFix":"# before\n@console_ns.route('/datasets/<uuid:library_id>/items')\n# after\n@console_ns.route('/datasets/<uuid:dataset_id>/items')","handlingStrategy":"validation","validationCode":"RBAC_DATASET_PATH_PARAMS = {'dataset_id', 'resource_id', 'pipeline_id'}\n\ndef route_supports_dataset_rbac(view_args: dict) -> bool:\n    return bool(set(view_args) & RBAC_DATASET_PATH_PARAMS)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding a dataset-scoped route, name a path param dataset_id/resource_id/pipeline_id or extend the extractor.","Add a unit test over _extract_resource_id for every new dataset-scoped route's path args.","Do not attach RBACResourceScope.DATASET to routes that are not dataset-addressed."],"tags":["rbac","routing","dataset","programming-error"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}