Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 9eb4dff

Browse files
committed
Update MutationsBatchError
1 parent 016285a commit 9eb4dff

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

google/cloud/bigtable/batcher.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@
3737
class MutationsBatchError(Exception):
3838
"""Error in the batch request"""
3939

40-
def __init__(self, status_codes):
41-
self.errors = [
42-
from_grpc_status(status_code.code, status_code.message)
43-
for status_code in status_codes
44-
if status_code.code != 0
45-
]
46-
self.message = "Errors in batch mutations."
40+
def __init__(self, message, exc):
41+
self.exc = exc
42+
self.message = message
4743
super().__init__(self.message)
4844

4945

@@ -312,7 +308,12 @@ def flush_rows(self, rows_to_flush=None):
312308
responses.append(result)
313309

314310
if has_error:
315-
raise MutationsBatchError(status_codes=responses)
311+
exc = [
312+
from_grpc_status(status_code.code, status_code.message)
313+
for status_code in responses
314+
if status_code.code != 0
315+
]
316+
raise MutationsBatchError(message="Errors in batch mutations.", exc=exc)
316317

317318
return responses
318319

tests/unit/test_batcher.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ def test_mutations_batcher_response_with_error_codes():
243243
with pytest.raises(MutationsBatchError) as exc:
244244
mutation_batcher.flush()
245245
assert exc.value.message == "Errors in batch mutations."
246-
assert len(exc.value.errors) == 2
246+
assert len(exc.value.exc) == 2
247247

248-
assert exc.value.errors[0].message == mocked_response[0].message
249-
assert exc.value.errors[1].message == mocked_response[1].message
248+
assert exc.value.exc[0].message == mocked_response[0].message
249+
assert exc.value.exc[1].message == mocked_response[1].message
250250

251251

252252
def test_mutations_batcher_flush_async_raises_exception():
@@ -266,10 +266,10 @@ def test_mutations_batcher_flush_async_raises_exception():
266266
with pytest.raises(MutationsBatchError) as exc:
267267
mutation_batcher.flush_async()
268268
assert exc.value.message == "Errors in batch mutations."
269-
assert len(exc.value.errors) == 2
269+
assert len(exc.value.exc) == 2
270270

271-
assert exc.value.errors[0].message == mocked_response[0].message
272-
assert exc.value.errors[1].message == mocked_response[1].message
271+
assert exc.value.exc[0].message == mocked_response[0].message
272+
assert exc.value.exc[1].message == mocked_response[1].message
273273

274274

275275
class _Instance(object):

0 commit comments

Comments
 (0)