code: def abort_transaction(self):
          
          self._check_ended()
  
          state = self._transaction.state
          if state is _TxnState.NONE:
              raise InvalidOperation("No transaction started")
          elif state is _TxnState.STARTING:
              # Server transaction was never started, no need to send a command.
              self._transaction.state = _TxnState.ABORTED
              return
          elif state is _TxnState.ABORTED:
              raise InvalidOperation("Cannot call abortTransaction twice")
          elif state in (_TxnState.COMMITTED, _TxnState.COMMITTED_EMPTY):
              raise InvalidOperation(
                  "Cannot call abortTransaction after calling commitTransaction")
  
          try:
              self._finish_transaction_with_retry("abortTransaction", False)
          except (OperationFailure, ConnectionFailure):
              # The transactions spec says to ignore abortTransaction errors.
              pass
          finally:
              self._transaction.state = _TxnState.ABORTED
docs: Abort a multi-statement transaction.
  
          .. versionadded:: 3.7