Skip to content

Commit ca42fdf

Browse files
committed
Update batch/transaction/query to hold client.
Update batch/transaction to push themselves onto client's stack, rather than batches. Updated API-invoking methods to take 'client', rather than 'connection', falling back to the client held by self. See #944.
1 parent 583d1ce commit ca42fdf

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

gcloud/datastore/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def dataset_id(self):
102102
103103
:rtype: str
104104
"""
105-
return self._dataset_id
105+
return self._dataset_id or self._client.dataset_id
106106

107107
@property
108108
def namespace(self):
@@ -111,7 +111,7 @@ def namespace(self):
111111
:rtype: string or None
112112
:returns: the namespace assigned to this query
113113
"""
114-
return self._namespace
114+
return self._namespace or self._client.namespace
115115

116116
@namespace.setter
117117
def namespace(self, value):

gcloud/datastore/test_transaction.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _makeOne(self, client):
2626

2727
def test_ctor(self):
2828
from gcloud.datastore._datastore_v1_pb2 import Mutation
29+
from gcloud.datastore.test_batch import _Client
2930

3031
_DATASET = 'DATASET'
3132
connection = _Connection()
@@ -40,6 +41,7 @@ def test_ctor(self):
4041

4142
def test_current(self):
4243
from gcloud.datastore.test_client import _NoCommitBatch
44+
from gcloud.datastore.test_batch import _Client
4345
_DATASET = 'DATASET'
4446
connection = _Connection()
4547
client = _Client(_DATASET, connection)
@@ -65,6 +67,7 @@ def test_current(self):
6567
self.assertTrue(xact2.current() is None)
6668

6769
def test_begin(self):
70+
from gcloud.datastore.test_batch import _Client
6871
_DATASET = 'DATASET'
6972
connection = _Connection(234)
7073
client = _Client(_DATASET, connection)
@@ -74,6 +77,7 @@ def test_begin(self):
7477
self.assertEqual(connection._begun, _DATASET)
7578

7679
def test_begin_tombstoned(self):
80+
from gcloud.datastore.test_batch import _Client
7781
_DATASET = 'DATASET'
7882
connection = _Connection(234)
7983
client = _Client(_DATASET, connection)
@@ -88,6 +92,7 @@ def test_begin_tombstoned(self):
8892
self.assertRaises(ValueError, xact.begin)
8993

9094
def test_rollback(self):
95+
from gcloud.datastore.test_batch import _Client
9196
_DATASET = 'DATASET'
9297
connection = _Connection(234)
9398
client = _Client(_DATASET, connection)
@@ -98,6 +103,7 @@ def test_rollback(self):
98103
self.assertEqual(connection._rolled_back, (_DATASET, 234))
99104

100105
def test_commit_no_auto_ids(self):
106+
from gcloud.datastore.test_batch import _Client
101107
_DATASET = 'DATASET'
102108
connection = _Connection(234)
103109
client = _Client(_DATASET, connection)
@@ -109,6 +115,7 @@ def test_commit_no_auto_ids(self):
109115
self.assertEqual(xact.id, None)
110116

111117
def test_commit_w_auto_ids(self):
118+
from gcloud.datastore.test_batch import _Client
112119
_DATASET = 'DATASET'
113120
_KIND = 'KIND'
114121
_ID = 123
@@ -127,6 +134,7 @@ def test_commit_w_auto_ids(self):
127134
self.assertEqual(entity.key.path, [{'kind': _KIND, 'id': _ID}])
128135

129136
def test_context_manager_no_raise(self):
137+
from gcloud.datastore.test_batch import _Client
130138
_DATASET = 'DATASET'
131139
connection = _Connection(234)
132140
client = _Client(_DATASET, connection)
@@ -217,8 +225,3 @@ def _push_batch(self, batch):
217225

218226
def _pop_batch(self):
219227
return self._batches.pop(0)
220-
221-
@property
222-
def current_batch(self):
223-
if self._batches:
224-
return self._batches[0]

0 commit comments

Comments
 (0)