From a1a877fd9bf1ed0fade58f5afd146bbb0f3180df Mon Sep 17 00:00:00 2001 From: mattnowzari Date: Fri, 31 Jan 2025 08:47:10 -0500 Subject: [PATCH 1/5] Fix to connector_sync_job_update_stats to ensure undefined metadata field gets passed to client as {} and not None --- connectors/es/index.py | 2 +- tests/es/test_index.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/connectors/es/index.py b/connectors/es/index.py index b8570ad54..c5309458e 100644 --- a/connectors/es/index.py +++ b/connectors/es/index.py @@ -130,7 +130,7 @@ async def connector_sync_job_update_stats( self.client.connector.sync_job_update_stats, connector_sync_job_id=sync_job_id, body=ingestion_stats, - metadata=metadata, + metadata=metadata if metadata else {}, ) ) diff --git a/tests/es/test_index.py b/tests/es/test_index.py index ee84ea9ca..60fd7cd88 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -408,7 +408,7 @@ async def test_es_api_connector_sync_job_claim(): async def test_es_api_connector_sync_job_update_stats(): sync_job_id = "sync_job_id_test" ingestion_stats = {"ingestion": "stat"} - metadata = {"meta": "data"} + metadata = None # make sure metadata gets passed as '{}' if undefined es_api = ESApi(elastic_config=config) es_api.client = AsyncMock() @@ -416,5 +416,5 @@ async def test_es_api_connector_sync_job_update_stats(): await es_api.connector_sync_job_update_stats(sync_job_id, ingestion_stats, metadata) es_api.client.connector.sync_job_update_stats.assert_called_once_with( - connector_sync_job_id=sync_job_id, body=ingestion_stats, metadata=metadata + connector_sync_job_id=sync_job_id, body=ingestion_stats, metadata={} ) From e91f338e4f1359e5f4c66cddfb6bda27ff288f9e Mon Sep 17 00:00:00 2001 From: Elastic Machine Date: Fri, 31 Jan 2025 13:58:48 +0000 Subject: [PATCH 2/5] make autoformat --- tests/es/test_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/es/test_index.py b/tests/es/test_index.py index 60fd7cd88..777e9356d 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -408,7 +408,7 @@ async def test_es_api_connector_sync_job_claim(): async def test_es_api_connector_sync_job_update_stats(): sync_job_id = "sync_job_id_test" ingestion_stats = {"ingestion": "stat"} - metadata = None # make sure metadata gets passed as '{}' if undefined + metadata = None # make sure metadata gets passed as '{}' if undefined es_api = ESApi(elastic_config=config) es_api.client = AsyncMock() From 950c79e8d766c70d585b21bf1556ab9647ef577b Mon Sep 17 00:00:00 2001 From: mattnowzari Date: Fri, 31 Jan 2025 10:24:26 -0500 Subject: [PATCH 3/5] Added original test case back --- tests/es/test_index.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/es/test_index.py b/tests/es/test_index.py index 777e9356d..98d66fb5d 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -404,6 +404,21 @@ async def test_es_api_connector_sync_job_claim(): ) +@pytest.mark.asyncio +async def test_es_api_connector_sync_job_update_stats_with_metadata(): + sync_job_id = "sync_job_id_test" + ingestion_stats = {"ingestion": "stat"} + metadata = {"meta": "data"} + + es_api = ESApi(elastic_config=config) + es_api.client = AsyncMock() + + await es_api.connector_sync_job_update_stats(sync_job_id, ingestion_stats, metadata) + + es_api.client.connector.sync_job_update_stats.assert_called_once_with( + connector_sync_job_id=sync_job_id, body=ingestion_stats, metadata=metadata + ) + @pytest.mark.asyncio async def test_es_api_connector_sync_job_update_stats(): sync_job_id = "sync_job_id_test" From b5d79fe61a30d3b149029f165a3b44b90bcaedc2 Mon Sep 17 00:00:00 2001 From: mattnowzari Date: Fri, 31 Jan 2025 10:25:33 -0500 Subject: [PATCH 4/5] Renamed new test to be more descriptive --- tests/es/test_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/es/test_index.py b/tests/es/test_index.py index 98d66fb5d..5f2a25a46 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -420,7 +420,7 @@ async def test_es_api_connector_sync_job_update_stats_with_metadata(): ) @pytest.mark.asyncio -async def test_es_api_connector_sync_job_update_stats(): +async def test_es_api_connector_sync_job_update_stats_metadata_as_none(): sync_job_id = "sync_job_id_test" ingestion_stats = {"ingestion": "stat"} metadata = None # make sure metadata gets passed as '{}' if undefined From fc9bb0b86f9c5b9f785cedac9d5fd54ecd434eb9 Mon Sep 17 00:00:00 2001 From: Elastic Machine Date: Fri, 31 Jan 2025 15:29:57 +0000 Subject: [PATCH 5/5] make autoformat --- tests/es/test_index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/es/test_index.py b/tests/es/test_index.py index 5f2a25a46..66653903c 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -419,6 +419,7 @@ async def test_es_api_connector_sync_job_update_stats_with_metadata(): connector_sync_job_id=sync_job_id, body=ingestion_stats, metadata=metadata ) + @pytest.mark.asyncio async def test_es_api_connector_sync_job_update_stats_metadata_as_none(): sync_job_id = "sync_job_id_test"