From ecd5e8082ff4e56ff2d778489858b9f27aa30be4 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 4 Nov 2026 08:32:38 +0000 Subject: [PATCH] Make openai_conversation repair issues unique per config entry (#190312) --- .../components/openai_conversation/entity.py | 3 +- .../openai_conversation/test_ai_task.py | 81 ++++++++++++++----- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/openai_conversation/entity.py b/homeassistant/components/openai_conversation/entity.py index 30fafb9fe8ca..8ee061e9f083 100644 --- a/homeassistant/components/openai_conversation/entity.py +++ b/homeassistant/components/openai_conversation/entity.py @@ -737,7 +737,8 @@ class OpenAIBaseLLMEntity(Entity): ir.async_create_issue( self.hass, DOMAIN, - "organization_verification_required", + f"organization_verification_required_{self.entry.entry_id}", + config_entry_id=self.entry.entry_id, is_fixable=False, is_persistent=False, learn_more_url="https://help.openai.com/en/articles/10910291-api-organization-verification", diff --git a/tests/components/openai_conversation/test_ai_task.py b/tests/components/openai_conversation/test_ai_task.py index 0e1ce17fe0ed..61f04d551491 100644 --- a/tests/components/openai_conversation/test_ai_task.py +++ b/tests/components/openai_conversation/test_ai_task.py @@ -22,8 +22,10 @@ from homeassistant.components.openai_conversation.const import ( CONF_STORE_RESPONSES, CONF_VERBOSITY, CONF_WEB_SEARCH, + RECOMMENDED_AI_TASK_OPTIONS, RECOMMENDED_DECISION_MODEL, ) +from homeassistant.config_entries import ConfigSubentryData from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from homeassistant.exceptions import HomeAssistantError @@ -538,7 +540,9 @@ async def test_generate_image( assert image_data.filename == "2025-06-14_155900_test_task.png" assert ( - issue_registry.async_get_issue(DOMAIN, "organization_verification_required") + issue_registry.async_get_issue( + DOMAIN, f"organization_verification_required_{mock_config_entry.entry_id}" + ) is None ) @@ -550,28 +554,63 @@ async def test_repair_issue( entity_registry: er.EntityRegistry, issue_registry: ir.IssueRegistry, ) -> None: - """Test that repair issue is raised when verification is required.""" - with ( - patch( - "openai.resources.responses.AsyncResponses.create", - side_effect=PermissionDeniedError( - response=httpx2.Response( - status_code=403, request=httpx2.Request(method="GET", url="") - ), - body=None, - message="Please click on Verify Organization.", + """Test the verification repair issue is raised and linked per entry.""" + other_entry = MockConfigEntry( + title="OpenAI 2", + domain=DOMAIN, + data={"api_key": "other"}, + version=mock_config_entry.version, + minor_version=mock_config_entry.minor_version, + subentries_data=[ + ConfigSubentryData( + data=RECOMMENDED_AI_TASK_OPTIONS, + subentry_type="ai_task_data", + title="Other AI Task", + unique_id=None, ), - ), - pytest.raises(HomeAssistantError, match="Error talking to OpenAI"), - ): - await ai_task.async_generate_image( - hass, - task_name="Test Task", - entity_id="ai_task.openai_ai_task", - instructions="Generate test image", - ) + ], + ) + other_entry.add_to_hass(hass) + with patch("openai.resources.models.AsyncModels.list", new_callable=AsyncMock): + assert await hass.config_entries.async_setup(other_entry.entry_id) + await hass.async_block_till_done() - assert issue_registry.async_get_issue(DOMAIN, "organization_verification_required") + with patch( + "openai.resources.responses.AsyncResponses.create", + side_effect=PermissionDeniedError( + response=httpx2.Response( + status_code=403, request=httpx2.Request(method="GET", url="") + ), + body=None, + message="Please click on Verify Organization.", + ), + ): + for entity_id in ("ai_task.openai_ai_task", "ai_task.other_ai_task"): + with pytest.raises(HomeAssistantError, match="Error talking to OpenAI"): + await ai_task.async_generate_image( + hass, + task_name="Test Task", + entity_id=entity_id, + instructions="Generate test image", + ) + + for entry in (mock_config_entry, other_entry): + issue = issue_registry.async_get_issue( + DOMAIN, f"organization_verification_required_{entry.entry_id}" + ) + assert issue is not None + assert issue.config_entry_id == entry.entry_id + assert issue.translation_key == "organization_verification_required" + + await hass.config_entries.async_remove(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert not issue_registry.async_get_issue( + DOMAIN, f"organization_verification_required_{mock_config_entry.entry_id}" + ) + assert issue_registry.async_get_issue( + DOMAIN, f"organization_verification_required_{other_entry.entry_id}" + ) @pytest.mark.parametrize(