Bug for _index_documents_actions when the batch is too large #38987
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
needs-author-feedback
Workflow: More information is needed from author to address the issue.
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Search
Describe the bug
The exception's handling will trigger keyerror for error_map
Function: def _index_documents_actions(self, actions: List[IndexAction], **kwargs: Any) -> List[IndexingResult]:
The key reason is the index() function will expect to pop error_map from kwargs, so you have to include it in the kwargs
To Reproduce
Steps to reproduce the behavior:
`
read json file
`
Expected behavior
Items should be splitted by half and get inserted to the index
Screenshots
Additional context
I fixed the hanlding by having the error_map in the kwargs:
`
def _index_documents_actions(self, actions: List[IndexAction], **kwargs: Any) -> List[IndexingResult]:
error_map = {413: RequestEntityTooLargeError}
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
kwargs["error_map"] = error_map
batch = IndexBatch(actions=actions)
try:
batch_response = self._client.documents.index(batch=batch, **kwargs)
return cast(List[IndexingResult], batch_response.results)
except RequestEntityTooLargeError:
if len(actions) == 1:
raise
pos = round(len(actions) / 2)
batch_response_first_half = self._index_documents_actions(
actions=actions[:pos], **kwargs
)
if batch_response_first_half:
result_first_half = batch_response_first_half
else:
result_first_half = []
batch_response_second_half = self._index_documents_actions(
actions=actions[pos:], **kwargs
)
if batch_response_second_half:
result_second_half = batch_response_second_half
else:
result_second_half = []
result_first_half.extend(result_second_half)
return result_first_half
`
The text was updated successfully, but these errors were encountered: