Skip to content

Commit d489900

Browse files
authored
Merge pull request #625 from sanders41/raise-for-status
Add missing raise_for_stats when timeout is None
2 parents 5ecae3a + b521059 commit d489900

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

meilisearch_python_async/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ async def wait_for_task(
296296
response = await http_requests.get(url)
297297
status = TaskResult(**response.json())
298298
if status.status in ("succeeded", "failed"):
299+
if raise_for_status and status.status == "failed":
300+
raise MeilisearchTaskFailedError(f"Task {task_id} failed")
299301
return status
300302
await sleep(interval_in_ms / 1000)
301303

tests/test_task.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,37 @@ async def test_wait_for_task_raise_for_status_true(empty_index, small_movies):
363363
assert update.status == "succeeded"
364364

365365

366+
async def test_wait_for_task_raise_for_status_true_no_timeout(
367+
empty_index, small_movies, base_url, monkeypatch
368+
):
369+
async def mock_get_response(*args, **kwargs):
370+
task = {
371+
"uid": args[1].split("/")[1],
372+
"index_uid": "7defe207-8165-4b69-8170-471456e295e0",
373+
"status": "failed",
374+
"task_type": "indexDeletion",
375+
"details": {"deletedDocuments": 30},
376+
"error": None,
377+
"canceled_by": None,
378+
"duration": "PT0.002765250S",
379+
"enqueued_at": "2023-06-09T01:03:48.311936656Z",
380+
"started_at": "2023-06-09T01:03:48.314143377Z",
381+
"finished_at": "2023-06-09T01:03:48.316536088Z",
382+
}
383+
384+
return httpx.Response(
385+
200, json=task, request=httpx.Request("get", url=f"{base_url}/{args[1]}")
386+
)
387+
388+
index = await empty_index()
389+
response = await index.add_documents(small_movies)
390+
monkeypatch.setattr(AsyncClient, "get", mock_get_response)
391+
with pytest.raises(MeilisearchTaskFailedError):
392+
await wait_for_task(
393+
index.http_client, response.task_uid, raise_for_status=True, timeout_in_ms=None
394+
)
395+
396+
366397
async def test_wait_for_task_raise_for_status_false(
367398
empty_index, small_movies, base_url, monkeypatch
368399
):

0 commit comments

Comments
 (0)