{"record":{"id":"9fe603c381d912c2","repo":"roboflow/supervision","slug":"all-or-none-of-the-mask-fields-must-be-none","errorCode":null,"errorMessage":"All or none of the 'mask' fields must be None","messagePattern":"All or none of the 'mask' fields must be None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":2444,"sourceCode":"\n        for detections in detections_list:\n            _validate_detections_fields(\n                xyxy=detections.xyxy,\n                mask=detections.mask,\n                confidence=detections.confidence,\n                class_id=detections.class_id,\n                tracker_id=detections.tracker_id,\n                data=detections.data,\n            )\n\n        xyxy = np.vstack([d.xyxy for d in detections_list])\n\n        def stack_mask_or_none() -> npt.NDArray[np.generic] | CompactMask | None:\n            masks = [d.mask for d in detections_list]\n            if all(m is None for m in masks):\n                return None\n            if any(m is None for m in masks):\n                raise ValueError(\"All or none of the 'mask' fields must be None\")\n            if all(isinstance(m, CompactMask) for m in masks):\n                return CompactMask.merge(cast(list[CompactMask], masks))\n            if all(not isinstance(m, CompactMask) for m in masks):\n                # All-dense: preserve backward-compatible dense stacking.\n                return cast(\n                    npt.NDArray[np.generic], np.vstack([np.asarray(m) for m in masks])\n                )\n            # Mixed dense and CompactMask: convert dense masks to CompactMask to\n            # avoid materialising a full (N, H, W) stack.\n            compact_image_shapes = {\n                m.image_shape for m in masks if isinstance(m, CompactMask)\n            }\n            if len(compact_image_shapes) != 1:\n                raise ValueError(\n                    \"Cannot merge CompactMask objects with different image shapes: \"\n                    f\"{sorted(compact_image_shapes)}\"\n                )\n            image_shape: tuple[int, int] = next(iter(compact_image_shapes))","sourceCodeStart":2426,"sourceCodeEnd":2462,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L2426-L2462","documentation":"Error \"All or none of the 'mask' fields must be None\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/detection/core.py:2444 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every Detections object being merged either has a mask or none of them do; do not mix masked and unmasked Detections.","If only some detections have masks, either compute masks for all of them or drop the mask field from all before merging."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}