GeezerVison is showing github.com — fix(bigtable): validate DirectRow and table match in MutationsBatcher.mutate by mutianf · Pull Request #18874 · googleapis/google-cloud-python
Conversation
mutianf
commented
Oct 27, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Validate that rows passed to MutationsBatcher.mutate(row) (and by extension MutationsBatcher.mutate_rows(rows)) are instances of DirectRow and are not bound to a different table, matching the existing validation in Table.mutate_rows().
Problem
When MutationsBatcher was refactored to wrap self.table._table_impl.mutations_batcher(...) directly (#18200) instead of delegating to self.table.mutate_rows(...), two row-validation checks from Table.mutate_rows() were dropped:
DirectRow type check (TypeError): Passing a ConditionalRow to batcher.mutate(cond_row) called cond_row._get_mutations() with the default state=None, which returns self._false_pb_mutations and unconditionally sends false-branch mutations via MutateRows without evaluating the row filter predicate. Passing an AppendRow raised a raw AttributeError: 'AppendRow' object has no attribute '_get_mutations' instead of TypeError.
- Table match check (
TableMismatchError): Passing a DirectRow bound to another table silently sent its mutations to batcher.table instead of raising TableMismatchError.
Solution
- Validate
isinstance(row, DirectRow) in MutationsBatcher.mutate(), raising TypeError("Bulk processing can not be applied for conditional or append mutations.") if not.
- Validate
row.table is None or row.table.name == self.table.name in MutationsBatcher.mutate(), raising TableMismatchError if the row belongs to a different table.
- Document
:raises: (TypeError and TableMismatchError) on MutationsBatcher.mutate() and MutationsBatcher.mutate_rows().
Test Plan
- Added unit tests in
packages/google-cloud-bigtable/tests/unit/v2_client/test_batcher.py:
test_mutations_batcher_mutate_w_bound_table_row
test_mutations_batcher_mutate_wrong_row_type (ConditionalRow and AppendRow across mutate and mutate_rows, verifying no mutations are queued)
test_mutations_batcher_mutate_table_mismatch (cross-table DirectRow across mutate and mutate_rows)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gemini-code-assist[bot] reacted with eyes emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces validation checks in MutationsBatcher.mutate to ensure that only DirectRow instances are processed and that the row's table matches the batcher's table. Corresponding unit tests have been added to verify these validations. The review feedback suggests using f-strings instead of % formatting for better readability and correcting a typo ('can not' to 'cannot') in the error message.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
daniel-sanche
pushed a commit
that referenced
this pull request
Oct 30, 2026
….mutate (#18874)
## Summary
Validate that rows passed to `MutationsBatcher.mutate(row)` (and by
extension `MutationsBatcher.mutate_rows(rows)`) are instances of
`DirectRow` and are not bound to a different table, matching the
existing validation in `Table.mutate_rows()`.
### Problem
When `MutationsBatcher` was refactored to wrap
`self.table._table_impl.mutations_batcher(...)` directly (#18200)
instead of delegating to `self.table.mutate_rows(...)`, two
row-validation checks from `Table.mutate_rows()` were dropped:
1. **`DirectRow` type check (`TypeError`)**: Passing a `ConditionalRow`
to `batcher.mutate(cond_row)` called `cond_row._get_mutations()` with
the default `state=None`, which returns `self._false_pb_mutations` and
unconditionally sends false-branch mutations via `MutateRows` without
evaluating the row filter predicate. Passing an `AppendRow` raised a raw
`AttributeError: 'AppendRow' object has no attribute '_get_mutations'`
instead of `TypeError`.
2. **Table match check (`TableMismatchError`)**: Passing a `DirectRow`
bound to another table silently sent its mutations to `batcher.table`
instead of raising `TableMismatchError`.
### Solution
- Validate `isinstance(row, DirectRow)` in `MutationsBatcher.mutate()`,
raising `TypeError("Bulk processing can not be applied for conditional
or append mutations.")` if not.
- Validate `row.table is None or row.table.name == self.table.name` in
`MutationsBatcher.mutate()`, raising `TableMismatchError` if the row
belongs to a different table.
- Document `:raises:` (`TypeError` and `TableMismatchError`) on
`MutationsBatcher.mutate()` and `MutationsBatcher.mutate_rows()`.
## Test Plan
- Added unit tests in
`packages/google-cloud-bigtable/tests/unit/v2_client/test_batcher.py`:
- `test_mutations_batcher_mutate_w_bound_table_row`
- `test_mutations_batcher_mutate_wrong_row_type` (`ConditionalRow` and
`AppendRow` across `mutate` and `mutate_rows`, verifying no mutations
are queued)
- `test_mutations_batcher_mutate_table_mismatch` (cross-table
`DirectRow` across `mutate` and `mutate_rows`)
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|