{"record":{"id":"902e02a1e3901b1d","repo":"HumanSignal/label-studio","slug":"selecteditems-must-be-dict-all-true-false","errorCode":null,"errorMessage":"selectedItems must be dict: {\"all\": [true|false], \"excluded | included\": [...task_ids...]}. Found type: {type(selected)} with value: {selected}","messagePattern":"selectedItems must be dict: (.+?)\\. Found type: (.+?) with value: (.+?)","errorType":"validation","errorClass":"DataManagerException","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/functions.py","lineNumber":316,"sourceCode":"        # 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)\n                except Exception as e:\n                    logger.error(f'Error parsing selectedItems: {e}')\n                    raise DataManagerException(\n                        'selectedItems must be JSON encoded string for dict: {\"all\": [true|false], '\n                        '\"excluded | included\": [...task_ids...]}. '\n                        f'Found: {selected}'\n                    )\n            else:\n                raise DataManagerException(\n                    'selectedItems must be dict: {\"all\": [true|false], '\n                    '\"excluded | included\": [...task_ids...]}. '\n                    f'Found type: {type(selected)} with value: {selected}'\n                )\n        filters = data.get('filters', None)\n        ordering = data.get('ordering', [])\n        prepare_params = PrepareParams(\n            project=project.id, selectedItems=selected, data=data, filters=filters, ordering=ordering, request=request\n        )\n    return prepare_params\n\n\ndef get_prepared_queryset(request, project):\n    prepare_params = get_prepare_params(request, project)\n    queryset = Task.prepared.only_filtered(prepare_params=prepare_params)\n    return queryset\n\n","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/functions.py#L298-L334","documentation":"get_prepare_params requires selectedItems to be a dict (or a JSON string that parses to the expected shape). If the value is neither a string nor a dict — e.g. a list, number, or bool — it raises DataManagerException stating the required dict shape and the offending type/value.","triggerScenarios":"Passing selectedItems as a bare list [1,2], an integer id, true/false, or null directly in the request body instead of the wrapper object {\"all\":bool,\"excluded|included\":[ids]}.","commonSituations":"Frontend code sending the raw selected-ids array; forgetting to wrap ids in the all/excluded/included envelope; schema drift between an older API version (plain id list) and the current one.","solutions":["Wrap the ids: send {\"all\": false, \"included\": [ids]} or {\"all\": true, \"excluded\": [ids]}`","Ensure the client serializes an object, not an array, for selectedItems","Check the API version/docs for the expected selectedItems schema","Add client-side validation that typeof selectedItems === 'object' && !Array.isArray(...)"],"exampleFix":"// before\n{\"selectedItems\": [12, 34]}\n// after\n{\"selectedItems\": {\"all\": false, \"included\": [12, 34]}}","handlingStrategy":"type-guard","validationCode":"const sel = payload.selectedItems;\nif (sel === null || typeof sel !== 'object' || Array.isArray(sel)) throw new Error('selectedItems must be {\"all\":bool,\"included|excluded\":[ids]}');","typeGuard":"const isSelectedItemsDict = (v) => typeof v === 'object' && v !== null && !Array.isArray(v) && typeof v.all === 'boolean';","tryCatchPattern":"try { await submit(payload); } catch (e) { if (/selectedItems must be dict/.test(e.message)) { payload.selectedItems = { all: false, included: payload.selectedItems }; await submit(payload); } else { throw e; } }","preventionTips":["Always wrap ids in the {all, included|excluded} envelope","Reject arrays at the form-serialization layer","Keep client types aligned with the current API schema","Unit-test request builders against the documented shape"],"tags":["api","data-manager","request-format","type-error"],"backgroundTag":"invalid-request-payload-shape","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}