Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions datastore/google/cloud/datastore/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,14 @@ def rollback(self, project, transaction_id):
:type transaction_id: str
:param transaction_id: The transaction ID returned from
:meth:`begin_transaction`.

:rtype: :class:`.datastore_pb2.RollbackResponse`
:returns: The returned protobuf response object.
"""
request = _datastore_pb2.RollbackRequest()
request.transaction = transaction_id
# Nothing to do with this response, so just execute the method.
self._datastore_api.rollback(project, request)
# Response is empty (i.e. no fields) but we return it anyway.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return self._datastore_api.rollback(project, request)

def allocate_ids(self, project, key_pbs):
"""Obtain backend-generated IDs for a set of keys.
Expand Down
1 change: 1 addition & 0 deletions datastore/google/cloud/datastore/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def rollback(self):
- Sets the current transaction's ID to None.
"""
try:
# No need to use the response it contains nothing.
self._client._connection.rollback(self.project, self._id)
finally:
super(Transaction, self).rollback()
Expand Down
25 changes: 15 additions & 10 deletions datastore/unit_tests/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,26 +767,31 @@ def test_commit_w_transaction(self):
def test_rollback_ok(self):
from google.cloud.proto.datastore.v1 import datastore_pb2

PROJECT = 'PROJECT'
TRANSACTION = b'xact'

project = 'PROJECT'
transaction = b'xact'
rsp_pb = datastore_pb2.RollbackResponse()

# Create mock HTTP and client with response.
http = Http({'status': '200'}, rsp_pb.SerializeToString())
client = mock.Mock(_http=http, spec=['_http'])

# Make request.
conn = self._make_one(client)
URI = '/'.join([
response = conn.rollback(project, transaction)

# Check the result and verify the callers.
self.assertEqual(response, rsp_pb)
uri = '/'.join([
conn.api_base_url,
conn.API_VERSION,
'projects',
PROJECT + ':rollback',
project + ':rollback',
])
self.assertIsNone(conn.rollback(PROJECT, TRANSACTION))
cw = http._called_with
self._verify_protobuf_call(cw, URI, conn)
rq_class = datastore_pb2.RollbackRequest
request = rq_class()
self._verify_protobuf_call(cw, uri, conn)
request = datastore_pb2.RollbackRequest()
request.ParseFromString(cw['body'])
self.assertEqual(request.transaction, TRANSACTION)
self.assertEqual(request.transaction, transaction)

def test_allocate_ids_empty(self):
from google.cloud.proto.datastore.v1 import datastore_pb2
Expand Down