8000 Renaming datastore Batch.mutation to changes. · googleapis/google-cloud-python@0949183 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0949183

Browse files
committed
Renaming datastore Batch.mutation to changes.
This is towards the switch to `v1beta3` where the `Mutation` container no longer holds a list of insert/update/upsert/etc. mutations (as `Entity` pb's) but instead holds a single one. The list is moved onto the `CommitRequest` message definition. Plan to follow up with methods to abstract away getting the list of inserts, upserts, deletes, etc. as well as a method for adding a new mutation of a given type to the `changes` accumulator.
1 parent ae01c3a commit 0949183

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

gcloud/datastore/batch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def connection(self):
9999
return self._client.connection
100100

101101
@property
102-
def mutation(self):
102+
def changes(self):
103103
"""Getter for the current mutation.
104104
105105
Every batch is committed with a single Mutation
@@ -146,10 +146,10 @@ def put(self, entity):
146146
raise ValueError("Key must be from same dataset as batch")
147147

148148
if entity.key.is_partial:
149-
entity_pb = self.mutation.insert_auto_id.add()
149+
entity_pb = self.changes.insert_auto_id.add()
150150
self._partial_key_entities.append(entity)
151151
else:
152-
entity_pb = self.mutation.upsert.add()
152+
entity_pb = self.changes.upsert.add()
153153

154154
_assign_entity_to_pb(entity_pb, entity)
155155

@@ -169,7 +169,7 @@ def delete(self, key):
169169
raise ValueError("Key must be from same dataset as batch")
170170

171171
key_pb = helpers._prepare_key_for_request(key.to_protobuf())
172-
self.mutation.delete.add().CopyFrom(key_pb)
172+
self.changes.delete.add().CopyFrom(key_pb)
173173

174174
def begin(self):
175175
"""No-op
@@ -186,7 +186,7 @@ def commit(self):
186186
context manager.
187187
"""
188188
response = self.connection.commit(
189-
self.dataset_id, self.mutation, self._id)
189+
self.dataset_id, self.changes, self._id)
190190
# If the back-end returns without error, we are guaranteed that
191191
# the response's 'insert_auto_id_key' will match (length and order)
192192
# the request's 'insert_auto_id` entities, which are derived from

gcloud/datastore/test_batch.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_ctor(self):
3737
self.assertEqual(batch.connection, connection)
3838
self.assertEqual(batch.namespace, _NAMESPACE)
3939
self.assertTrue(batch._id is None)
40-
self.assertTrue(isinstance(batch.mutation, Mutation))
40+
self.assertTrue(isinstance(batch.changes, Mutation))
4141
self.assertEqual(batch._partial_key_entities, [])
4242

4343
def test_current(self):
@@ -89,12 +89,12 @@ def test_put_entity_w_partial_key(self):
8989

9090
batch.put(entity)
9191

92-
insert_auto_ids = list(batch.mutation.insert_auto_id)
92+
insert_auto_ids = list(batch.changes.insert_auto_id)
9393
self.assertEqual(len(insert_auto_ids), 1)
9494
self.assertEqual(insert_auto_ids[0].key, key._key)
95-
upserts = list(batch.mutation.upsert)
95+
upserts = list(batch.changes.upsert)
9696
self.assertEqual(len(upserts), 0)
97-
deletes = list(batch.mutation.delete)
97+
deletes = list(batch.changes.delete)
9898
self.assertEqual(len(deletes), 0)
9999
self.assertEqual(batch._partial_key_entities, [entity])
100100

@@ -115,9 +115,9 @@ def test_put_entity_w_completed_key(self):
115115

116116
batch.put(entity)
117117

118-
insert_auto_ids = list(batch.mutation.insert_auto_id)
118+
insert_auto_ids = list(batch.changes.insert_auto_id)
119119
self.assertEqual(len(insert_auto_ids), 0)
120-
upserts = list(batch.mutation.upsert)
120+
upserts = list(batch.changes.upsert)
121121
self.assertEqual(len(upserts), 1)
122122

123123
upsert = upserts[0]
@@ -131,7 +131,7 @@ def test_put_entity_w_completed_key(self):
131131
self.assertFalse(props['spam'].list_value[2].indexed)
132132
self.assertFalse('frotz' in props)
133133

134-
deletes = list(batch.mutation.delete)
134+
deletes = list(batch.changes.delete)
135135
self.assertEqual(len(deletes), 0)
136136

137137
def test_put_entity_w_completed_key_prefixed_dataset_id(self):
@@ -151,9 +151,9 @@ def test_put_entity_w_completed_key_prefixed_dataset_id(self):
151151

152152
batch.put(entity)
153153

154-
insert_auto_ids = list(batch.mutation.insert_auto_id)
154+
insert_auto_ids = list(batch.changes.insert_auto_id)
155155
self.assertEqual(len(insert_auto_ids), 0)
156-
upserts = list(batch.mutation.upsert)
156+
upserts = list(batch.changes.upsert)
157157
self.assertEqual(len(upserts), 1)
158158

159159
upsert = upserts[0]
@@ -167,7 +167,7 @@ def test_put_entity_w_completed_key_prefixed_dataset_id(self):
167167
self.assertFalse(props['spam'].list_value[2].indexed)
168168
self.assertFalse('frotz' in props)
169169

170-
deletes = list(batch.mutation.delete)
170+
deletes = list(batch.changes.delete)
171171
self.assertEqual(len(deletes), 0)
172172

173173
def test_delete_w_partial_key(self):
@@ -198,11 +198,11 @@ def test_delete_w_completed_key(self):
198198

199199
batch.delete(key)
200200

201-
insert_auto_ids = list(batch.mutation.insert_auto_id)
201+
insert_auto_ids = list(batch.changes.insert_auto_id)
202202
self.assertEqual(len(insert_auto_ids), 0)
203-
upserts = list(batch.mutation.upsert)
203+
upserts = list(batch.changes.upsert)
204204
self.assertEqual(len(upserts), 0)
205-
deletes = list(batch.mutation.delete)
205+
deletes = list(batch.changes.delete)
206206
self.assertEqual(len(deletes), 1)
207207
self.assertEqual(deletes[0], key._key)
208208

@@ -215,11 +215,11 @@ def test_delete_w_completed_key_w_prefixed_dataset_id(self):
215215

216216
batch.delete(key)
217217

218-
insert_auto_ids = list(batch.mutation.insert_auto_id)
218+
insert_auto_ids = list(batch.changes.insert_auto_id)
219219
self.assertEqual(len(insert_auto_ids), 0)
220-
upserts = list(batch.mutation.upsert)
220+
upserts = list(batch.changes.upsert)
221221
self.assertEqual(len(upserts), 0)
222-
deletes = list(batch.mutation.delete)
222+
deletes = list(batch.changes.delete)
223223
self.assertEqual(len(deletes), 1)
224224
self.assertEqual(deletes[0], key._key)
225225

@@ -232,7 +232,7 @@ def test_commit(self):
232232
batch.commit()
233233

234234
self.assertEqual(connection._committed,
235-
[(_DATASET, batch.mutation, None)])
235+
[(_DATASET, batch.changes, None)])
236236

237237
def test_commit_w_partial_key_entities(self):
238238
_DATASET = 'DATASET'
@@ -248,7 +248,7 @@ def test_commit_w_partial_key_entities(self):
248248
batch.commit()
249249

250250
self.assertEqual(connection._committed,
251-
[(_DATASET, batch.mutation, None)])
251+
[(_DATASET, batch.changes, None)])
252252
self.assertFalse(entity.key.is_partial)
253253
self.assertEqual(entity.key._id, _NEW_ID)
254254

@@ -268,15 +268,15 @@ def test_as_context_mgr_wo_error(self):
268268

269269
self.assertEqual(list(client._batches), [])
270270

271-
insert_auto_ids = list(batch.mutation.insert_auto_id)
271+
insert_auto_ids = list(batch.changes.insert_auto_id)
272272
self.assertEqual(len(insert_auto_ids), 0)
273-
upserts = list(batch.mutation.upsert)
273+
upserts = list(batch.changes.upsert)
274274
self.assertEqual(len(upserts), 1)
275275
self.assertEqual(upserts[0].key, key._key)
276-
deletes = list(batch.mutation.delete)
276+
deletes = list(batch.changes.delete)
277277
self.assertEqual(len(deletes), 0)
278278
self.assertEqual(connection._committed,
279-
[(_DATASET, batch.mutation, None)])
279+
[(_DATASET, batch.changes, None)])
280280

281281
def test_as_context_mgr_nested(self):
282282
_DATASET = 'DATASET'
@@ -301,25 +301,25 @@ def test_as_context_mgr_nested(self):
301301

302302
self.assertEqual(list(client._batches), [])
303303

304-
insert_auto_ids = list(batch1.mutation.insert_auto_id)
304+
insert_auto_ids = list(batch1.changes.insert_auto_id)
305305
self.assertEqual(len(insert_auto_ids), 0)
306-
upserts = list(batch1.mutation.upsert)
306+
upserts = list(batch1.changes.upsert)
307307
self.assertEqual(len(upserts), 1)
308308
self.assertEqual(upserts[0].key, key1._key)
309-
deletes = list(batch1.mutation.delete)
309+
deletes = list(batch1.changes.delete)
310310
self.assertEqual(len(deletes), 0)
311311

312-
insert_auto_ids = list(batch2.mutation.insert_auto_id)
312+
insert_auto_ids = list(batch2.changes.insert_auto_id)
313313
self.assertEqual(len(insert_auto_ids), 0)
314-
upserts = list(batch2.mutation.upsert)
314+
upserts = list(batch2.changes.upsert)
315315
self.assertEqual(len(upserts), 1)
316316
self.assertEqual(upserts[0].key, key2._key)
317-
deletes = list(batch2.mutation.delete)
317+
deletes = list(batch2.changes.delete)
318318
self.assertEqual(len(deletes), 0)
319319

320320
self.assertEqual(connection._committed,
321-
[(_DATASET, batch2.mutation, None),
322-
(_DATASET, batch1.mutation, None)])
321+
[(_DATASET, batch2.changes, None),
322+
(_DATASET, batch1.changes, None)])
323323

324324
def test_as_context_mgr_w_error(self):
325325
_DATASET = 'DATASET'
@@ -341,12 +341,12 @@ def test_as_context_mgr_w_error(self):
341341

342342
self.assertEqual(list(client._batches), [])
343343

344-
insert_auto_ids = list(batch.mutation.insert_auto_id)
344+
insert_auto_ids = list(batch.changes.insert_auto_id)
345345
self.assertEqual(len(insert_auto_ids), 0)
346-
upserts = list(batch.mutation.upsert)
346+
upserts = list(batch.changes.upsert)
347347
self.assertEqual(len(upserts), 1)
348348
self.assertEqual(upserts[0].key, key._key)
349-
deletes = list(batch.mutation.delete)
349+
deletes = list(batch.changes.delete)
350350
self.assertEqual(len(deletes), 0)
351351
self.assertEqual(connection._committed, [])
352352

gcloud/datastore/test_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,14 @@ def test_put_multi_existing_batch_w_completed_key(self):
647647
result = client.put_multi([entity])
648648

649649
self.assertEqual(result, None)
650-
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
651-
upserts = list(CURR_BATCH.mutation.upsert)
650+
self.assertEqual(len(CURR_BATCH.changes.insert_auto_id), 0)
651+
upserts = list(CURR_BATCH.changes.upsert)
652652
self.assertEqual(len(upserts), 1)
653653
self.assertEqual(upserts[0].key, key.to_protobuf())
654654
properties = list(upserts[0].property)
655655
self.assertEqual(properties[0].name, 'foo')
656656
self.assertEqual(properties[0].value.string_value, u'bar')
657-
self.assertEqual(len(CURR_BATCH.mutation.delete), 0)
657+
self.assertEqual(len(CURR_BATCH.changes.delete), 0)
658658

659659
def test_delete(self):
660660
_called_with = []
@@ -708,9 +708,9 @@ def test_delete_multi_w_existing_batch(self):
708708
result = client.delete_multi([key])
709709

710710
self.assertEqual(result, None)
711-
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
712-
self.assertEqual(len(CURR_BATCH.mutation.upsert), 0)
713-
deletes = list(CURR_BATCH.mutation.delete)
711+
self.assertEqual(len(CURR_BATCH.changes.insert_auto_id), 0)
712+
self.assertEqual(len(CURR_BATCH.changes.upsert), 0)
713+
deletes = list(CURR_BATCH.changes.delete)
714714
self.assertEqual(len(deletes), 1)
715715
self.assertEqual(deletes[0], key._key)
716716
self.assertEqual(len(client.connection._commit_cw), 0)
@@ -726,9 +726,9 @@ def test_delete_multi_w_existing_transaction(self):
726726
result = client.delete_multi([key])
727727

728728
self.assertEqual(result, None)
729-
self.assertEqual(len(CURR_XACT.mutation.insert_auto_id), 0)
730-
self.assertEqual(len(CURR_XACT.mutation.upsert), 0)
731-
deletes = list(CURR_XACT.mutation.delete)
729+
self.assertEqual(len(CURR_XACT.changes.insert_auto_id), 0)
730+
self.assertEqual(len(CURR_XACT.changes.upsert), 0)
731+
deletes = list(CURR_XACT.changes.delete)
732732
self.assertEqual(len(deletes), 1)
733733
self.assertEqual(deletes[0], key._key)
734734
self.assertEqual(len(client.connection._commit_cw), 0)

gcloud/datastore/test_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_ctor_defaults(self):
3535
self.assertEqual(xact.connection, connection)
3636
self.assertEqual(xact.id, None)
3737
self.assertEqual(xact._status, self._getTargetClass()._INITIAL)
38-
self.assertTrue(isinstance(xact.mutation, Mutation))
38+
self.assertTrue(isinstance(xact.changes, Mutation))
3939
self.assertEqual(len(xact._partial_key_entities), 0)
4040

4141
def test_current(self):

0 commit comments

Comments
 (0)
0