{"record":{"id":"a4bfa1fea3a016f6","repo":"home-assistant/core","slug":"item-item-id-not-found","errorCode":null,"errorMessage":"Item {item_id} not found.","messagePattern":"Item (.+?) not found\\.","errorType":"exception","errorClass":"ItemNotFound","httpStatus":null,"severity":"warning","filePath":"homeassistant/components/assist_pipeline/pipeline.py","lineNumber":1992,"sourceCode":"        return item.to_json()\n\n    @override\n    async def async_delete_item(self, item_id: str) -> None:\n        \"\"\"Delete item.\"\"\"\n        if self._preferred_item == item_id:\n            raise PipelinePreferred(item_id)\n        await super().async_delete_item(item_id)\n\n    @callback\n    def async_get_preferred_item(self) -> str:\n        \"\"\"Get the id of the preferred item.\"\"\"\n        return self._preferred_item\n\n    @callback\n    def async_set_preferred_item(self, item_id: str) -> None:\n        \"\"\"Set the preferred pipeline.\"\"\"\n        if item_id not in self.data:\n            raise ItemNotFound(item_id)\n        self._preferred_item = item_id\n        self._async_schedule_save()\n\n    @callback\n    @override\n    def _data_to_save(self) -> SerializedPipelineStorageCollection:\n        \"\"\"Return JSON-compatible date for storing to file.\"\"\"\n        base_data = super()._base_data_to_save()\n        return {\n            \"items\": base_data[\"items\"],\n            \"preferred_item\": self._preferred_item,\n        }\n\n\nclass PipelineStorageCollectionWebsocket(\n    StorageCollectionWebsocket[PipelineStorageCollection]\n):\n    \"\"\"Class to expose storage collection management over websocket.\"\"\"","sourceCodeStart":1974,"sourceCodeEnd":2010,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/assist_pipeline/pipeline.py#L1974-L2010","documentation":"ItemNotFound (a CollectionError from homeassistant.helpers.collection) is raised by async_set_preferred_item when the given item_id is not a key in the pipeline collection's data. It guards the preferred pointer from being set to a pipeline that does not exist.","triggerScenarios":"Calling async_set_preferred_item (or the corresponding WebSocket/UI action) with a pipeline id that was deleted, never existed, or came from stale state (e.g. a satellite's stored pipeline reference).","commonSituations":"Automations or voice satellites holding a cached pipeline id after the pipeline was recreated; race where the pipeline is deleted between a list call and the set-preferred call; typos in manually crafted ids.","solutions":["List current pipelines (pipeline_data.async_pipelines_items / UI) and pass a valid id.","Refresh any cached pipeline ids in satellite/automation state after pipelines are created or deleted.","Catch ItemNotFound and fall back to the current preferred item id."],"exampleFix":"# before\nawait pipeline_data.async_set_preferred_item(stored_id)  # stale id -> raises\n\n# after\nfrom homeassistant.helpers.collection import ItemNotFound\ntry:\n    await pipeline_data.async_set_preferred_item(stored_id)\nexcept ItemNotFound:\n    await pipeline_data.async_set_preferred_item(pipeline_data.async_get_preferred_item())","handlingStrategy":"validation","validationCode":"if item_id not in pipeline_data.data:\n    item_id = pipeline_data.async_get_preferred_item()  # fall back to current preferred","typeGuard":null,"tryCatchPattern":"from homeassistant.helpers.collection import ItemNotFound\ntry:\n    await pipeline_data.async_set_preferred_item(item_id)\nexcept ItemNotFound:\n    ...  # refresh pipeline list, reselect","preventionTips":["Always resolve ids from the live collection (pipeline_data.data keys) rather than cached state.","After deleting pipelines, refresh any UI or satellite holding pipeline ids."],"tags":["assist-pipeline","storage","collection","stale-reference"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}