From 1d0c72e0d9ff80c673f3b483dbd9e653f05e7fd5 Mon Sep 17 00:00:00 2001 From: iluvdata <86066778+iluvdata@users.noreply.github.com> Date: Wed, 8 Jul 2026 16:45:42 -0400 Subject: [PATCH] Improve in code comments for file_upload (#169768) Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: Martin Hjelmare --- homeassistant/components/file_upload/__init__.py | 6 +++++- tests/components/file_upload/test_init.py | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/file_upload/__init__.py b/homeassistant/components/file_upload/__init__.py index 7cbd89cd261c..067e87f559f7 100644 --- a/homeassistant/components/file_upload/__init__.py +++ b/homeassistant/components/file_upload/__init__.py @@ -36,7 +36,11 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) def process_uploaded_file(hass: HomeAssistant, file_id: str) -> Generator[Path]: """Get an uploaded file. - File is removed at the end of the context. + File is removed at the end of the context. Should be run on the executor thread pool. + Create a wrapper function and call that wrapper function using + hass.async_add_executor_job. Running this function directly by scheduling an executor + job will result in loop blocking teardown code not running on the executor but + rather in the loop. """ if DOMAIN not in hass.data: raise ValueError("File does not exist") diff --git a/tests/components/file_upload/test_init.py b/tests/components/file_upload/test_init.py index 2bf68f00ea0f..49daf1b3b63f 100644 --- a/tests/components/file_upload/test_init.py +++ b/tests/components/file_upload/test_init.py @@ -17,8 +17,8 @@ from tests.components.image_upload import TEST_IMAGE from tests.typing import ClientSessionGenerator -@pytest.fixture -async def uploaded_file_dir( +@pytest.fixture(name="uploaded_file_dir") +async def upload_file_dir( hass: HomeAssistant, hass_client: ClientSessionGenerator ) -> Path: """Test uploading and using a file.""" @@ -51,7 +51,6 @@ async def test_using_file(hass: HomeAssistant, uploaded_file_dir) -> None: assert file_path.parent == uploaded_file_dir assert file_path.read_bytes() == TEST_IMAGE.read_bytes() - # Test it's removed assert not uploaded_file_dir.exists()