Logic error in bulk helper: incorrect conditional in _process_bulk_chunk_success
**Elasticsearch version:** N/A (client-side issue)
**Python version:** All supported versions
**Description:**
There's a logic error in the `_process_bulk_chunk_success` function in `elasticsearch/helpers/actions.py` at line 329.
**Current code:**
https://github.com/elastic/elasticsearch-py/blob/6df97e3c21adffeb33d0a4c64dc784e618d85f41/elasticsearch/helpers/actions.py#L329-L332
```python
if ok or not errors: # Line 329 - INCORRECT LOGIC
# if we are not just recording all errors to be able to raise
# them all at once, yield items individually
yield ok, {op_type: item}
```
**Problem:** The condition ok or not errors is logically incorrect. When errors is empty (no errors collected yet), not errors evaluates to True, causing the code to yield items even when they might have failed. This defeats the purpose of collecting all errors before raising them. The issue is:
When ok=False (item failed) and errors=[] (empty list, first failure), the condition ok or not errors evaluates to False or True = True, so it yields the failed item as if it succeeded.
This can lead to incorrect bulk operation behavior where failures are not properly tracked.
Expected behavior: The function should only yield items when they are successful (ok=True), regardless of whether errors have been collected yet.
**Suggested fix:** Change line 329 to use AND logic instead of OR:
`if ok and not errors:`
Or more simply:
`if ok:`
**Steps to reproduce:** This is in bulk operations where the first item succeeds but subsequent items fail - the error handling logic would be bypassed.
Line: https://github.com/elastic/elasticsearch-py/blob/6df97e3c21adffeb33d0a4c64dc784e618d85f41/elasticsearch/helpers/actions.py#L329
Function: _process_bulk_chunk_success
0 条评论