Exception class for bulk write errors. .. versionadded:: 2.7
| 282 | |
| 283 | |
| 284 | class BulkWriteError(OperationFailure): |
| 285 | """Exception class for bulk write errors. |
| 286 | |
| 287 | .. versionadded:: 2.7 |
| 288 | """ |
| 289 | |
| 290 | details: _DocumentOut |
| 291 | |
| 292 | def __init__(self, results: _DocumentOut) -> None: |
| 293 | super().__init__("batch op errors occurred", 65, results) |
| 294 | |
| 295 | def __reduce__(self) -> tuple[Any, Any]: |
| 296 | return self.__class__, (self.details,) |
| 297 | |
| 298 | @property |
| 299 | def timeout(self) -> bool: |
| 300 | # Check the last writeConcernError and last writeError to determine if this |
| 301 | # BulkWriteError was caused by a timeout. |
| 302 | wces = self.details.get("writeConcernErrors", []) |
| 303 | if wces and _wtimeout_error(wces[-1]): |
| 304 | return True |
| 305 | |
| 306 | werrs = self.details.get("writeErrors", []) |
| 307 | if werrs and werrs[-1].get("code") == 50: |
| 308 | return True |
| 309 | return False |
| 310 | |
| 311 | |
| 312 | class ClientBulkWriteException(OperationFailure): |
no outgoing calls