{{ message }}
Repository navigation
fix!: azure_ai_search - raise when Azure AI Search rejects documents in a batch - #4134
Open
ericdelorefice wants to merge 1 commit into
Open
ericdelorefice wants to merge 1 commit into
ericdelorefice wants to merge 1 commit into
Conversation
…in a batch upload_documents and merge_documents do not raise when individual documents fail: the service answers 207 Multi-Status and the SDK returns one IndexingResult per document with succeeded=False. write_documents and update_by_filter discarded that list and returned the full count, so rejected documents were reported as written or updated. Both now raise AzureAISearchDocumentStoreError naming the failed documents (first 10, then a count). Documents that were indexed stay indexed. Also corrects update_by_filter's error message, which said "delete".
ericdelorefice
requested review from
bogdankostic
and removed request for
a team
October 20, 2026 14:42
Contributor
Contributor
Coverage report (azure_ai_search)Click to see where and how coverage changedThis report was generated by python-coverage-comment-action |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related Issues
No issue. Found by reading
write_documents, following #3997, #4006 and #4027 in this repo. #3618 (by @HussainNizamani, for #3579) fixed a close relative in the Valkey store: a batch where some documents failed was reported with the wrong count.Proposed Changes
SearchClient.upload_documentsandmerge_documentsdo not raise when individual documents fail. Azure AI Search answers the batch with 207 Multi-Status, and the SDK returns oneIndexingResultper document withsucceeded=Falseand astatus_code(its docstring lists 409 for a version conflict, 422 when the index is temporarily unavailable and 503 when the service is too busy). The SDK's ownSearchIndexingBufferedSenderreadssucceededand retries 409, 422 and 503, so the SDK treats these as real failures.write_documentsandupdate_by_filterdiscarded that list and returnedlen(...)of what they sent. So when Azure rejected some documents:write_documentsreturned the full count, andDocumentWriterreported every document as written. The rejected ones were simply missing from search afterwards, with nothing raised or logged.update_by_filterreturned the full count when some merges were refused.The Elasticsearch, OpenSearch and Weaviate stores in this repo already check per-item results on write and raise
DocumentStoreError.This PR adds a small helper that checks the returned results and raises
AzureAISearchDocumentStoreError(aDocumentStoreError) naming each failed document with its status code and message, capped at 10 lines plus "... and N more". It is called afterupload_documentsinwrite_documentsand aftermerge_documentsinupdate_by_filter. For example:Also in
update_by_filter: its error message said "Failed to delete documents by filter", which this new error now passes through, so it now says "Failed to update documents by filter".Breaking change
write_documentsandupdate_by_filternow raise where they used to return a count, when Azure reports any document as not indexed. Documents Azure did index stay indexed; only the call's result changes. Code that relied on these calls never raising for a partly failed batch will now see the error. Markedfix!:for the same reason as #3997, #4006 and #4027; happy to drop the!if you see it as a plain fix.How did you test it?
Unit tests in
tests/test_document_store.py, no Azure service needed. They use the realSearchClient; only the network is replaced, by arequestsadapter mounted on the SDK's ownRequestsTransportthat answers as the service does (207 with one result per document for a partly failed batch). The document failures are injected this way. I have not seen this against a live Azure AI Search service.test_write_documents_raises_when_documents_are_rejected: one of three documents rejected (503), and all three rejected (422).test_write_documents_error_lists_at_most_ten_rejected_documents: 50 rejected documents give 10 lines and "... and 40 more".test_update_by_filter_raises_when_documents_are_rejected: one merge refused with 409.HttpResponseError, and a successfulupdate_by_filterreturns 2 and sends the expected merge actions.The four rejection tests fail on
mainwithDID NOT RAISE DocumentStoreErrorand pass with the fix (checked three times each way). Outside the PR, I also checked that the SDK returns the 207 results without raising, and thatDocumentWriterin aPipelinereported 3 written onmainwhere Azure indexed 2.Not run: the 103 integration tests, which need a live Azure service.
Notes for the reviewer
delete_documents,delete_all_documentsanddelete_by_filteralso ignore the per-document results ofclient.delete_documents. I kept this PR to writes and updates and can do the delete methods as a follow-up if you want them to behave the same way.Checklist
This PR was written with AI assistance (Claude Code); the tests above were run before opening it.