algolia / algoliasearch-client-python

⚡️ A fully-featured and blazing-fast Python API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/python/?language=python
MIT License
196 stars 67 forks source link

fix: SearchIndex.replace_all_objects is stuck when using "safe" mode #482

Closed r0ro closed 4 years ago

r0ro commented 4 years ago
Q A
Bug fix? yes
New feature? no
BC breaks? no
Related Issue Fix #481
Need Doc update no

Describe your change

create new SearchIndex instance when creating a temporary index in replace_all_objects

as per doc: https://www.algolia.com/doc/api-reference/api-methods/replace-all-objects/,

when replacing all objects, a temporary index is used to store new data, and once ready it replace the original index.

There was an issue when replace_all_objects was called with 'safe' move:

What problem is this fixing?

Although it was working before, when tracked using the wrong index name, the indexing task is stuck with status notPublished. (maybe it's something that should also be fixed on the backend ?)

With this patch, instead of trying to patch SearchIndex copied instance, we create a new clean instance.

When updating a "dev" index, previous call history would be:

# save_objects calls
--> POST 1/indexes/dev_tmp_aNCOSqmzOQ/batch {'requests': [{'action': 'updateObject', 'body': ... }]}
<-- 200 / {'objectIDs': ['obj_1', ...], 'taskID': 81739652001}

# track task progress in wait call

--> GET 1/indexes/dev/task/81739652001 None
<-- 200 / {'status': 'notPublished', 'pendingTask': False}
--> GET 1/indexes/dev/task/81739652001 None
<-- 200 / {'status': 'notPublished', 'pendingTask': False}

[ ... ] forever

after the fix the task is tracked on the correct index:

# save_objects calls
--> POST 1/indexes/dev_tmp_aNCOSqmzOQ/batch {'requests': [{'action': 'updateObject', 'body': ... }]}
<-- 200 / {'objectIDs': ['obj_1', ...], 'taskID': 81739652001}

# track task progress in wait call

--> GET 1/indexes/dev_tmp_aNCOSqmzOQ/task/81739652001 None
<-- 200 / {'status': 'notPublished', 'pendingTask': False}
--> GET 1/indexes/dev_tmp_aNCOSqmzOQ/task/81739652001 None
<-- 200 / {'status': 'notPublished', 'pendingTask': False}

[ ... ]

--> GET 1/indexes/dev_tmp_aNCOSqmzOQ/task/81739652001 None
<-- 200 / {'status': 'published', 'pendingTask': False}
r0ro commented 4 years ago

alternate fix to #479

nunomaduro commented 4 years ago

Duplicated of: https://github.com/algolia/algoliasearch-client-python/pull/479.