From 9562f999f9b6717422f0b88df000187a3278faca Mon Sep 17 00:00:00 2001 From: Matt Nowzari Date: Fri, 31 Jan 2025 10:58:47 -0500 Subject: [PATCH] Fix to ESApi connector_sync_job_update_stats() to ensure undefined metadata passed as {} when undefined (#3170) Co-authored-by: Elastic Machine --- connectors/es/index.py | 2 +- tests/es/test_index.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/connectors/es/index.py b/connectors/es/index.py index 6beb2826b..3e7d7ac7f 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..66653903c 100644 --- a/tests/es/test_index.py +++ b/tests/es/test_index.py @@ -405,7 +405,7 @@ async def test_es_api_connector_sync_job_claim(): @pytest.mark.asyncio -async def test_es_api_connector_sync_job_update_stats(): +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"} @@ -418,3 +418,19 @@ async def test_es_api_connector_sync_job_update_stats(): 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_metadata_as_none(): + sync_job_id = "sync_job_id_test" + ingestion_stats = {"ingestion": "stat"} + metadata = None # make sure metadata gets passed as '{}' if undefined + + 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={} + )