diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index 52f269141b69..9642be52afc1 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -559,7 +559,7 @@ def _set_read_options(self, request, eventual): if eventual: opts.read_consistency = datastore_pb.ReadOptions.EVENTUAL elif transaction: - opts.transaction = transaction + opts.transaction = transaction.id() def _copy_deferred_keys(lookup_request, lookup_response): diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index ba68138bd1b8..5a5e8e085bbc 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -268,7 +268,7 @@ def test_lookup_single_key_empty_response_w_eventual_and_transaction(self): TRANSACTION = 'TRANSACTION' key_pb = Key(path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf() conn = self._makeOne() - conn.transaction(TRANSACTION) + conn.transaction(Transaction(TRANSACTION)) self.assertRaises( ValueError, conn.lookup, DATASET_ID, key_pb, eventual=True) @@ -281,7 +281,7 @@ def test_lookup_single_key_empty_response_w_transaction(self): key_pb = Key(path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf() rsp_pb = datastore_pb.LookupResponse() conn = self._makeOne() - conn.transaction(TRANSACTION) + conn.transaction(Transaction(TRANSACTION)) URI = '/'.join([ conn.API_BASE_URL, 'datastore', @@ -569,7 +569,7 @@ def test_run_query_wo_eventual_w_transaction(self): rsp_pb.batch.more_results = no_more rsp_pb.batch.entity_result_type = datastore_pb.EntityResult.FULL conn = self._makeOne() - conn.transaction(TRANSACTION) + conn.transaction(Transaction(TRANSACTION)) URI = '/'.join([ conn.API_BASE_URL, 'datastore', @@ -610,7 +610,7 @@ def test_run_query_w_eventual_and_transaction(self): rsp_pb.batch.more_results = no_more rsp_pb.batch.entity_result_type = datastore_pb.EntityResult.FULL conn = self._makeOne() - conn.transaction(TRANSACTION) + conn.transaction(Transaction(TRANSACTION)) self.assertRaises( ValueError, conn.run_query, DATASET_ID, q_pb, eventual=True) @@ -1174,3 +1174,12 @@ def request(self, **kw): self._called_with.append(kw) result, self._responses = self._responses[0], self._responses[1:] return result + + +class Transaction(object): + + def __init__(self, id): + self._id = id + + def id(self): + return self._id