{"record":{"id":"c1e0f1651ce40e93","repo":"roboflow/supervision","slug":"conflicting-metadata-for-key-key","errorCode":null,"errorMessage":"Conflicting metadata for key: '{key}'.","messagePattern":"Conflicting metadata for key: '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/utils/internal.py","lineNumber":648,"sourceCode":"                merged_metadata[key] = value\n                continue\n\n            other_value = merged_metadata[key]\n            if isinstance(value, np.ndarray) and isinstance(other_value, np.ndarray):\n                if not np.array_equal(merged_metadata[key], value):\n                    raise ValueError(\n                        f\"Conflicting metadata for key: '{key}': \"\n                        f\"{type(value)}, {type(other_value)}.\"\n                    )\n            elif isinstance(value, np.ndarray) or isinstance(other_value, np.ndarray):\n                # Since [] == np.array([]).\n                raise ValueError(\n                    f\"Conflicting metadata for key: '{key}': \"\n                    f\"{type(value)}, {type(other_value)}.\"\n                )\n            else:\n                if merged_metadata[key] != value:\n                    raise ValueError(f\"Conflicting metadata for key: '{key}'.\")\n\n    return merged_metadata\n\n\ndef get_data_item(\n    data: _DetectionDataType,\n    index: int | slice | list[int] | npt.NDArray[np.integer | np.bool_],\n) -> _DetectionDataType:\n    \"\"\"\n    Retrieve a subset of the data dictionary based on the given index.\n\n    Args:\n        data: The data dictionary of the Detections object.\n        index: The index or indices specifying the subset to retrieve.\n\n    Returns:\n        A subset of the data dictionary corresponding to the specified index.\n    \"\"\"","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/utils/internal.py#L630-L666","documentation":"Raised by merge_metadata when the same metadata key holds different non-array (scalar/plain) values in two Detections being merged. After the ndarray special cases, plain inequality of the existing merged value and the new value is treated as a conflict, because merge_metadata has no policy for choosing between competing scalars.","triggerScenarios":"sv.Detections.merge([d1, d2]) with d1.metadata={'video_id': 1} and d2.metadata={'video_id': 2}; also the internal pair merge in core.py:3462 and annotations merge (core.py:3366) when inputs come from different videos/cameras.","commonSituations":"Concatenating Detections accumulated from multiple videos or camera streams where each carries its own video_id/source_id; batching detections per frame with frame-index metadata and merging across frames; reusing a merge helper on heterogeneous batches.","solutions":["Merge only Detections that share the metadata value (group inputs by metadata before merging), e.g. group by d.metadata['video_id'] and merge within each group","Overwrite the conflicting key with a single intended value on all inputs before merge","Drop the per-source key from metadata if it is not needed post-merge"],"exampleFix":"# before\nmerged = sv.Detections.merge([d_v1, d_v2])  # video_id 1 vs 2\n# after\nfrom itertools import groupby\ngroups = {}\nfor d in detections_list:\n    groups.setdefault(d.metadata.get('video_id'), []).append(d)\nmerged = [sv.Detections.merge(g) for g in groups.values()]","handlingStrategy":"validation","validationCode":"def split_by_metadata(detections_list, key):\n    groups = {}\n    for d in detections_list:\n        groups.setdefault(d.metadata.get(key), []).append(d)\n    return list(groups.values())\n# merge within each group only","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Merge only Detections sharing identical metadata (group by the discriminating key first)","Overwrite the varying metadata key before merging when a single canonical value is acceptable","Design pipelines so merged batches share source/video/frame context"],"tags":["detections","metadata","merge","conflict"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}