From 63c37bd3a302582947501ee68c868d9edaf2685a Mon Sep 17 00:00:00 2001 From: Sebastian Husch Lee Date: Thu, 8 Jan 2026 11:40:49 +0100 Subject: [PATCH 1/2] Auto call warm_up at runtime --- .../downloaders/s3/s3_downloader.py | 3 +- .../tests/test_s3_downloader.py | 35 +++++++------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/integrations/amazon_bedrock/src/haystack_integrations/components/downloaders/s3/s3_downloader.py b/integrations/amazon_bedrock/src/haystack_integrations/components/downloaders/s3/s3_downloader.py index e790a51d8b..7ad228057b 100644 --- a/integrations/amazon_bedrock/src/haystack_integrations/components/downloaders/s3/s3_downloader.py +++ b/integrations/amazon_bedrock/src/haystack_integrations/components/downloaders/s3/s3_downloader.py @@ -142,8 +142,7 @@ def run( """ if self._storage is None: - msg = f"The component {self.__class__.__name__} was not warmed up. Call 'warm_up()' before calling run()." - raise RuntimeError(msg) + self.warm_up() filtered_documents = self._filter_documents_by_extensions(documents) if self.file_extensions else documents diff --git a/integrations/amazon_bedrock/tests/test_s3_downloader.py b/integrations/amazon_bedrock/tests/test_s3_downloader.py index 71f231f81a..4cb24df365 100644 --- a/integrations/amazon_bedrock/tests/test_s3_downloader.py +++ b/integrations/amazon_bedrock/tests/test_s3_downloader.py @@ -129,7 +129,6 @@ def test_to_dict_with_parameters(self, tmp_path): def test_run(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path)) - S3Downloader.warm_up(d) d._storage = mock_s3_storage docs = [ @@ -141,7 +140,7 @@ def test_run(self, tmp_path, mock_s3_storage, mock_boto3_session): def test_run_with_extensions(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), file_extensions=[".txt"]) - S3Downloader.warm_up(d) + d.warm_up() d._storage = mock_s3_storage docs = [ @@ -155,12 +154,10 @@ def test_run_with_extensions(self, tmp_path, mock_s3_storage, mock_boto3_session def test_run_with_input_file_meta_key(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), file_name_meta_key="custom_file_key") - S3Downloader.warm_up(d) + d.warm_up() d._storage = mock_s3_storage - docs = [ - Document(meta={"file_id": str(uuid4()), "custom_file_key": "a.txt"}), - ] + docs = [Document(meta={"file_id": str(uuid4()), "custom_file_key": "a.txt"})] out = d.run(documents=docs) assert len(out["documents"]) == 1 @@ -168,12 +165,10 @@ def test_run_with_input_file_meta_key(self, tmp_path, mock_s3_storage, mock_boto def test_run_with_s3_key_generation_function(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), s3_key_generation_function=s3_key_generation_function) - S3Downloader.warm_up(d) + d.warm_up() d._storage = mock_s3_storage - docs = [ - Document(meta={"file_id": str(uuid4()), "file_name": "a.txt"}), - ] + docs = [Document(meta={"file_id": str(uuid4()), "file_name": "a.txt"})] out = d.run(documents=docs) assert len(out["documents"]) == 1 assert out["documents"][0].meta["file_name"] == "a.txt" @@ -189,7 +184,7 @@ def test_run_with_s3_key_generation_function_and_file_extensions( s3_key_generation_function=s3_key_generation_function, file_extensions=[".txt"], ) - S3Downloader.warm_up(d) + d.warm_up() d._storage = mock_s3_storage docs = [ @@ -210,8 +205,6 @@ def test_run_with_s3_key_generation_function_and_file_extensions( def test_live_run(self, tmp_path, monkeypatch): d = S3Downloader(file_root_path=str(tmp_path)) monkeypatch.setenv("S3_DOWNLOADER_PREFIX", "") - S3Downloader.warm_up(d) - docs = [ Document(meta={"file_id": str(uuid4()), "file_name": "text-sample.txt"}), Document(meta={"file_id": str(uuid4()), "file_name": "document-sample.pdf"}), @@ -229,7 +222,7 @@ def test_live_run(self, tmp_path, monkeypatch): ) def test_live_run_with_no_documents(self, tmp_path): d = S3Downloader(file_root_path=str(tmp_path)) - S3Downloader.warm_up(d) + d.warm_up() docs = [] out = d.run(documents=docs) assert len(out["documents"]) == 0 @@ -247,7 +240,7 @@ def test_live_run_with_no_documents(self, tmp_path): def test_live_run_with_custom_meta_key(self, tmp_path, monkeypatch): d = S3Downloader(file_root_path=str(tmp_path), file_name_meta_key="custom_name") monkeypatch.setenv("S3_DOWNLOADER_PREFIX", "") - S3Downloader.warm_up(d) + d.warm_up() docs = [ Document(meta={"custom_name": "text-sample.txt"}), ] @@ -264,10 +257,8 @@ def test_live_run_with_prefix(self, tmp_path, monkeypatch): d = S3Downloader(file_root_path=str(tmp_path)) monkeypatch.setenv("S3_DOWNLOADER_PREFIX", "subfolder/") - S3Downloader.warm_up(d) - docs = [ - Document(meta={"file_name": "employees.json"}), - ] + d.warm_up() + docs = [Document(meta={"file_name": "employees.json"})] out = d.run(documents=docs) assert len(out["documents"]) == 1 assert out["documents"][0].meta["file_name"] == "employees.json" @@ -286,10 +277,8 @@ def test_live_run_with_s3_key_generation_function_and_file_extensions(self, tmp_ file_name_meta_key="file_name", s3_key_generation_function=s3_key_generation_function, ) - S3Downloader.warm_up(d) - docs = [ - Document(meta={"file_name": "dog.jpg"}), - ] + d.warm_up() + docs = [Document(meta={"file_name": "dog.jpg"})] out = d.run(documents=docs) assert len(out["documents"]) == 1 assert out["documents"][0].meta["file_name"] == "dog.jpg" From 4f67e558caa04e9097b55e25ab6334777332624d Mon Sep 17 00:00:00 2001 From: Sebastian Husch Lee Date: Thu, 8 Jan 2026 11:42:14 +0100 Subject: [PATCH 2/2] Remove unnecessary calls --- .../amazon_bedrock/tests/test_s3_downloader.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/integrations/amazon_bedrock/tests/test_s3_downloader.py b/integrations/amazon_bedrock/tests/test_s3_downloader.py index 4cb24df365..d1692b3c4a 100644 --- a/integrations/amazon_bedrock/tests/test_s3_downloader.py +++ b/integrations/amazon_bedrock/tests/test_s3_downloader.py @@ -140,7 +140,6 @@ def test_run(self, tmp_path, mock_s3_storage, mock_boto3_session): def test_run_with_extensions(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), file_extensions=[".txt"]) - d.warm_up() d._storage = mock_s3_storage docs = [ @@ -154,7 +153,6 @@ def test_run_with_extensions(self, tmp_path, mock_s3_storage, mock_boto3_session def test_run_with_input_file_meta_key(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), file_name_meta_key="custom_file_key") - d.warm_up() d._storage = mock_s3_storage docs = [Document(meta={"file_id": str(uuid4()), "custom_file_key": "a.txt"})] @@ -165,7 +163,6 @@ def test_run_with_input_file_meta_key(self, tmp_path, mock_s3_storage, mock_boto def test_run_with_s3_key_generation_function(self, tmp_path, mock_s3_storage, mock_boto3_session): d = S3Downloader(file_root_path=str(tmp_path), s3_key_generation_function=s3_key_generation_function) - d.warm_up() d._storage = mock_s3_storage docs = [Document(meta={"file_id": str(uuid4()), "file_name": "a.txt"})] @@ -184,7 +181,6 @@ def test_run_with_s3_key_generation_function_and_file_extensions( s3_key_generation_function=s3_key_generation_function, file_extensions=[".txt"], ) - d.warm_up() d._storage = mock_s3_storage docs = [ @@ -222,9 +218,7 @@ def test_live_run(self, tmp_path, monkeypatch): ) def test_live_run_with_no_documents(self, tmp_path): d = S3Downloader(file_root_path=str(tmp_path)) - d.warm_up() - docs = [] - out = d.run(documents=docs) + out = d.run(documents=[]) assert len(out["documents"]) == 0 @pytest.mark.integration @@ -241,9 +235,7 @@ def test_live_run_with_custom_meta_key(self, tmp_path, monkeypatch): d = S3Downloader(file_root_path=str(tmp_path), file_name_meta_key="custom_name") monkeypatch.setenv("S3_DOWNLOADER_PREFIX", "") d.warm_up() - docs = [ - Document(meta={"custom_name": "text-sample.txt"}), - ] + docs = [Document(meta={"custom_name": "text-sample.txt"})] out = d.run(documents=docs) assert len(out["documents"]) == 1 assert out["documents"][0].meta["custom_name"] == "text-sample.txt" @@ -256,7 +248,6 @@ def test_live_run_with_custom_meta_key(self, tmp_path, monkeypatch): def test_live_run_with_prefix(self, tmp_path, monkeypatch): d = S3Downloader(file_root_path=str(tmp_path)) monkeypatch.setenv("S3_DOWNLOADER_PREFIX", "subfolder/") - d.warm_up() docs = [Document(meta={"file_name": "employees.json"})] out = d.run(documents=docs)