GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@mutianf mutianf commented Oct 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@mutianf
mutianf requested a review from a team as a code owner October 27, 2026 21:37
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Oct 27, 2026
View reviewed changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread packages/google-cloud-bigtable/google/cloud/bigtable/batcher.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mutianf
mutianf force-pushed the fix-batcher-row-validation branch from 6f5cff0 to be1f1fd Compare October 28, 2026 19:30
daniel-sanche
daniel-sanche approved these changes Oct 29, 2026
View reviewed changes
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 29, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 29, 2026
mutianf added 2 commits October 29, 2026 22:40
@mutianf
fix(bigtable): validate DirectRow and table match in MutationsBatcher…
53878ed
….mutate
@mutianf
style(bigtable): use f-string and 'cannot' in MutationsBatcher.mutate
de7e4e4
@mutianf
mutianf force-pushed the fix-batcher-row-validation branch from be1f1fd to de7e4e4 Compare October 30, 2026 02:41
@mutianf
mutianf enabled auto-merge (squash) October 30, 2026 02:41
@mutianf
mutianf merged commit 8aa6d4d into main Oct 30, 2026
57 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mutianf
mutianf deleted the fix-batcher-row-validation branch October 30, 2026 03:19
@release-please release-please Bot mentioned this pull request Oct 30, 2026
chore(main): release google-cloud-bigtable 2.50.3 #18829
Open
daniel-sanche pushed a commit that referenced this pull request Oct 30, 2026
@mutianf @daniel-sanche
fix(bigtable): validate DirectRow and table match in MutationsBatcher…
b14c858
….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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@daniel-sanche daniel-sanche daniel-sanche approved these changes
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

3 participants

@mutianf @daniel-sanche @yoshi-kokoro
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.