ClientBulkWriteException.has_error_label should behave correctly

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      ClientBulkWriteException.has_error_label should behave correctly. Currently our code which checks for error labels has to handle ClientBulkWriteException specially and inspect the "error" property.

                          if isinstance(exc, ClientBulkWriteException) and exc.error:
                              retryable_write_error_exc = isinstance(
                                  exc.error, PyMongoError
                              ) and exc.error.has_error_label("RetryableWriteError")
                          else:
                              retryable_write_error_exc = exc.has_error_label("RetryableWriteError")
      

      https://github.com/mongodb/mongo-python-driver/blob/3c786f5/pymongo/asynchronous/mongo_client.py#L2806-L2808

      This is a problem because ClientBulkWriteException violates the Liskov substitution principle. I suspect the NoWritesPerformed check doesn't work as intended because of this issue:

                          if not retryable_write_error_exc or self._is_not_eligible_for_retry():
                              if exc.has_error_label("NoWritesPerformed") and self._last_error:
                                  raise self._last_error from exc
                              else:
                                  raise
      

      Noticed while working on PYTHON-5505.

            Assignee:
            Unassigned
            Reporter:
            Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: