api-clients-automation icon indicating copy to clipboard operation
api-clients-automation copied to clipboard

fix(python): chunked_batch helper

Open kai687 opened this issue 1 year ago • 4 comments

🧭 What and Why

Fix a bug in the chunked_batch helper for the Python API client. The bug shows when using the replace_all_objects helper—the new index won't have all the records:

  • < 1,000 records: only the first record (0 % batch_size == 0) will be sent.
  • > 1,000 records: only the first 1 + n x 1,000 records will be sent. The records after the last integer multiple of batch_size won't be sent.

Changes included:

  • Send the request when the length of the request array reaches the batch_size, or when the end of the objects list is reached.
  • Change the type of the objects "list" in replace_all_objects and chunked_batch to be an Iterable instead of an explicit list. This makes it possible to use also with things like list comprehensions.

🧪 Test

No additional test added (didn't quite know how we could test this, as the API is mocked in these tests... we would have to test whether the replaced index has the correct records in it).

kai687 avatar May 07 '24 16:05 kai687

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch. You can still access the code generated on main via this commit.

algolia-bot avatar May 07 '24 16:05 algolia-bot

🚀 Deployed on https://66470a6b56a651806f08f68f--api-clients-automation.netlify.app

github-actions[bot] avatar May 16 '24 09:05 github-actions[bot]

@millotp @morganleroi don't want to bother you, but could you review this PR? It should fix a bug in the Python API client.

kai687 avatar May 17 '24 07:05 kai687

I think we have that issue in other clients too, i'll add a ticket to our backlog just to be sure

alternatively, a universal solution, might be to first build a list of list of batch by iterating over all objects, then iterating on the list to do the requests

shortcuts avatar May 17 '24 08:05 shortcuts

This should be addressed for all clients by #3154.

kai687 avatar Jun 11 '24 09:06 kai687