Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to ESApi connector_sync_job_update_stats() to ensure undefined metadata passed as {} when undefined #3170

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connectors/es/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},
)
)

Expand Down
18 changes: 17 additions & 1 deletion tests/es/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
mattnowzari marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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={}
)