{"record":{"id":"34283fbd1399c023","repo":"deepset-ai/haystack","slug":"invalid-component-device-type-type-device-nam","errorCode":null,"errorMessage":"Invalid component device type '{type(device).__name__}'. Must either be None or ComponentDevice.","messagePattern":"Invalid component device type '(.+?)'\\. Must either be None or ComponentDevice\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/utils/device.py","lineNumber":447,"sourceCode":"        if self._single_device is not None:\n            return self.from_single(self._single_device)\n\n        assert self._multiple_devices is not None\n        assert self._multiple_devices.first_device is not None\n        return self.from_single(self._multiple_devices.first_device)\n\n    @staticmethod\n    def resolve_device(device: Optional[\"ComponentDevice\"] = None) -> \"ComponentDevice\":\n        \"\"\"\n        Select a device for a component. If a device is specified, it's used. Otherwise, the default device is used.\n\n        :param device:\n            The provided device, if any.\n        :returns:\n            The resolved device.\n        \"\"\"\n        if not isinstance(device, ComponentDevice) and device is not None:\n            raise ValueError(\n                f\"Invalid component device type '{type(device).__name__}'. Must either be None or ComponentDevice.\"\n            )\n\n        if device is None:\n            device = ComponentDevice.from_single(_get_default_device())\n\n        return device\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"\n        Convert the component device representation to a JSON-serializable dictionary.\n\n        :returns:\n            The dictionary representation.\n        \"\"\"\n        if self._single_device is not None:\n            return {\"type\": \"single\", \"device\": str(self._single_device)}\n        if self._multiple_devices is not None:","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/device.py#L429-L465","documentation":"resolve_device() validates that the `device` argument is either None or a ComponentDevice instance. Passing any other type (str, torch.device, int, etc.) triggers this ValueError, since Haystack cannot infer how to map arbitrary objects onto its device abstraction.","triggerScenarios":"Calling resolve_device() with a raw string like \"cuda:0\", a torch.device object, an int, or any non-ComponentDevice value.","commonSituations":"Migrating from older Haystack versions where plain strings were accepted; passing a HF/torch device object directly; constructing a pipeline component config manually.","solutions":["Convert the value with ComponentDevice.from_str(\"cuda:0\") before passing it.","If you have multiple devices, use ComponentDevice.from_multiple(DeviceMap.from_dict(...)).","Pass None explicitly to let Haystack resolve the default device."],"exampleFix":"// before\nresolved = resolve_device(\"cuda:0\")\n// after\nfrom haystack.utils import ComponentDevice\nresolved = resolve_device(ComponentDevice.from_str(\"cuda:0\"))","handlingStrategy":"type-guard","validationCode":"from haystack.utils import ComponentDevice\nassert device is None or isinstance(device, ComponentDevice), f\"bad device: {type(device)}\"","typeGuard":"def is_component_device(d) -> bool:\n    return d is None or isinstance(d, ComponentDevice)","tryCatchPattern":"try:\n    resolved = resolve_device(device)\nexcept ValueError:\n    resolved = resolve_device(None)","preventionTips":["Always construct devices via ComponentDevice.from_str/from_multiple.","Never pass raw torch.device or strings to resolve_device.","Add isinstance checks at pipeline config boundaries."],"tags":["python","device","type-validation","haystack"],"backgroundTag":"invalid-argument-type","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}