diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index 13e299a16f93..cd04302496bd 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -165,23 +165,20 @@ def begin_transaction(self, dataset_id, serializable=False): return response.transaction - def rollback_transaction(self, dataset_id, transaction_id): - """Rollback an existing transaction. + def rollback_transaction(self, dataset_id): + """Rollback the connection's existing transaction. Raises a ``ValueError`` if the connection isn't currently in a transaction. :type dataset_id: string :param dataset_id: The dataset to which the transaction belongs. - - :type transaction_id: string - :param transaction_id: The ID of the transaction to roll back. """ if not self.transaction() or not self.transaction().id(): raise ValueError('No transaction to rollback.') request = datastore_pb.RollbackRequest() - request.transaction = transaction_id + request.transaction = self.transaction().id() # Nothing to do with this response, so just execute the method. self._rpc(dataset_id, 'rollback', request, datastore_pb.RollbackResponse) diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index f420af347bb4..ee151c261d0b 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -244,31 +244,27 @@ def test_begin_transaction_explicit_serialize(self): def test_rollback_transaction_wo_existing_transaction(self): DATASET_ID = 'DATASET' - TRANSACTION_ID = 'TRANSACTION' conn = self._makeOne() self.assertRaises(ValueError, - conn.rollback_transaction, DATASET_ID, TRANSACTION_ID) + conn.rollback_transaction, DATASET_ID) def test_rollback_transaction_w_existing_transaction_no_id(self): class Xact(object): def id(self): return None DATASET_ID = 'DATASET' - TRANSACTION_ID = 'TRANSACTION' conn = self._makeOne() conn.transaction(Xact()) self.assertRaises(ValueError, - conn.rollback_transaction, DATASET_ID, TRANSACTION_ID) + conn.rollback_transaction, DATASET_ID) def test_rollback_transaction_ok(self): from gcloud.datastore.connection import datastore_pb + DATASET_ID = 'DATASET' + TRANSACTION = 'xact' class Xact(object): def id(self): - return 'xact' - xact = object() - - DATASET_ID = 'DATASET' - TRANSACTION = 'TRANSACTION' + return TRANSACTION rsp_pb = datastore_pb.RollbackResponse() conn = self._makeOne() conn.transaction(Xact()) @@ -280,14 +276,13 @@ def id(self): 'rollback', ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) - self.assertEqual(conn.rollback_transaction(DATASET_ID, TRANSACTION), - None) + self.assertEqual(conn.rollback_transaction(DATASET_ID), None) cw = http._called_with self.assertEqual(cw['uri'], URI) self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '13', + 'Content-Length': '6', }) rq_class = datastore_pb.RollbackRequest request = rq_class()