Merge result of a single bulk write batch into the full result.
(
ops: list[tuple[str, Mapping[str, Any]]],
offset: int,
full_result: MutableMapping[str, Any],
result: Mapping[str, Any],
)
| 26 | |
| 27 | |
| 28 | def _merge_command( |
| 29 | ops: list[tuple[str, Mapping[str, Any]]], |
| 30 | offset: int, |
| 31 | full_result: MutableMapping[str, Any], |
| 32 | result: Mapping[str, Any], |
| 33 | ) -> None: |
| 34 | """Merge result of a single bulk write batch into the full result.""" |
| 35 | if result.get("error"): |
| 36 | full_result["error"] = result["error"] |
| 37 | |
| 38 | full_result["nInserted"] += result.get("nInserted", 0) |
| 39 | full_result["nDeleted"] += result.get("nDeleted", 0) |
| 40 | full_result["nMatched"] += result.get("nMatched", 0) |
| 41 | full_result["nModified"] += result.get("nModified", 0) |
| 42 | full_result["nUpserted"] += result.get("nUpserted", 0) |
| 43 | |
| 44 | write_errors = result.get("writeErrors") |
| 45 | if write_errors: |
| 46 | for doc in write_errors: |
| 47 | # Leave the server response intact for APM. |
| 48 | replacement = doc.copy() |
| 49 | original_index = doc["idx"] + offset |
| 50 | replacement["idx"] = original_index |
| 51 | # Add the failed operation to the error document. |
| 52 | replacement["op"] = ops[original_index][1] |
| 53 | full_result["writeErrors"].append(replacement) |
| 54 | |
| 55 | wce = _get_wce_doc(result) |
| 56 | if wce: |
| 57 | full_result["writeConcernErrors"].append(wce) |
| 58 | |
| 59 | |
| 60 | def _throw_client_bulk_write_exception( |
no test coverage detected