{"record":{"id":"2be0cd14f1d73a78","repo":"HumanSignal/label-studio","slug":"project-and-view-mismatch","errorCode":null,"errorMessage":"Project and View mismatch","messagePattern":"Project and View mismatch","errorType":"validation","errorClass":"DataManagerException","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/functions.py","lineNumber":289,"sourceCode":"        },\n    ]\n\n    result['columns'].append(data_root)\n\n    return result\n\n\ndef get_prepare_params(request, project):\n    \"\"\"This function extract prepare_params from\n    * view_id if it's inside of request data\n    * selectedItems, filters, ordering if they are in request and there is no view id\n    \"\"\"\n    # use filters and selected items from view\n    view_id = int_from_request(request.GET, 'view', 0) or int_from_request(request.data, 'view', 0)\n    if view_id > 0:\n        view = get_object_or_404(View, pk=view_id)\n        if view.project.pk != project.pk:\n            raise DataManagerException('Project and View mismatch')\n        prepare_params = view.get_prepare_tasks_params(add_selected_items=True)\n        prepare_params.request = request\n\n    # use filters and selected items from request if it's specified\n    else:\n        # query arguments from url\n        if 'query' in request.GET:\n            data = json.loads(unquote(request.GET['query']))\n        # data payload from body\n        else:\n            data = request.data\n\n        selected = data.get('selectedItems', {'all': True, 'excluded': []})\n        if not isinstance(selected, dict):\n            if isinstance(selected, str):\n                # try to parse JSON string\n                try:\n                    selected = json.loads(selected)","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/functions.py#L271-L307","documentation":"get_prepare_params in label_studio/data_manager/functions.py loads an optional saved View by id and applies its filters/selected items. When the View's project id differs from the project the request targets, it raises DataManagerException('Project and View mismatch') because a view must never be applied to another project's task queryset.","triggerScenarios":"A Data Manager API call (GET list, POST actions, or get_prepared_queryset) passes ?view=<id> (or view in request.data) whose View row belongs to project A while the URL/project parameter is project B.","commonSituations":"Hardcoded or stale view ids in scripts/automations; copying an integrations URL from one project to another; a view shared or serialized into another project after project deletion/recreation; frontend state referencing a view from a previously opened project.","solutions":["Use a view id that belongs to the same project as the request's project parameter","Re-fetch the correct view id for the target project via the views API (GET /api/storages or /api/datasets/views?project=<id>)","Remove the view parameter so filters come from the request itself","If the view was moved/cloned, recreate it in the target project and update stored references"],"exampleFix":"// before\nGET /api/tasks?project=12&view=77   # view 77 belongs to project 9\n// after\nGET /api/tasks?project=12&view=104  # view created under project 12","handlingStrategy":"validation","validationCode":"const res = await fetch(`/api/views/${viewId}`); const view = await res.json();\nif (String(view.project) !== String(projectId)) throw new Error(`View ${viewId} belongs to project ${view.project}, not ${projectId}`);","typeGuard":"const viewMatchesProject = (view, projectId) => view != null && String(view.project) === String(projectId);","tryCatchPattern":"try { const params = await getPrepareParams(...); } catch (e) { if (e instanceof DataManagerException && /Project and View mismatch/.test(e.message)) { reloadViewForProject(projectId); } else { throw e; } }","preventionTips":["Store view ids together with their project id and verify on use","Re-fetch views per project instead of caching a single global view id","Never copy Data Manager URLs between projects without clearing the ?view= param","In scripts, resolve the view by name within the target project each run"],"tags":["api","data-manager","parameter-validation","label-studio"],"backgroundTag":"project-view-mismatch","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}