Skip to content

fix(bigtable): preserve row key across ReadRowsResponse boundaries in chunk_stream - #18748

Open
mutianf wants to merge 1 commit into
googleapis:mainfrom
mutianf:fix-chunk-stream-cross-response-key
Open

mutianf wants to merge 1 commit into
googleapis:mainfrom
mutianf:fix-chunk-stream-cross-response-key

Conversation

@mutianf

@mutianf mutianf commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • current_key was reset to None at the start of each ReadRowsResponse inside chunk_stream. When a single row spans two response messages, the continuation chunk in the second response carries no row_key (protobuf bytes default b""), so current_key was set to b"" instead of the actual row key.
  • On commit_row, self._last_yielded_row_key = current_key wrote b"", corrupting the retry cursor. On any subsequent retryable error, _revise_request_rowset used b"" as last_seen_row_key, causing the already-committed row to be re-requested and yielded again.
  • Also fixes the dead-code guard if current_key is None → if not current_key: protobuf bytes fields default to b"", not None, so the old check never fired.

Fix: move current_key = None to before the outer async for resp loop so it persists across response boundaries. The sync autogen file is regenerated from the async source.

Test plan

  • Added test_chunk_stream_cross_response_row_key (async + autogen sync): constructs a two-response stream where the first response opens a row and the second commits it, then asserts _last_yielded_row_key equals the actual row key rather than b"".
  • All 310 unit/acceptance tests pass (pytest tests/unit/data/_async/test__read_rows.py tests/unit/data/_sync_autogen/test__read_rows.py tests/unit/data/_async/test_read_rows_acceptance.py tests/unit/data/_sync_autogen/test_read_rows_acceptance.py).

Change-Id: I5c94a4448cc24ee80e283f8ca93f21b8b35ccccd
@mutianf
mutianf requested a review from a team as a code owner October 17, 2026 03:25

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

Copy link
Copy Markdown
Contributor

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 fixes a bug in the chunk_stream method of the ReadRows operation where current_key was incorrectly reset to None at the start of each ReadRowsResponse. By moving the initialization of current_key outside of the response stream loop, the code now correctly handles rows that span across multiple responses when continuation chunks omit the row key. The changes are reflected in both the asynchronous implementation and the autogenerated synchronous counterpart, accompanied by new unit tests to verify the fix. I have no further feedback to provide as the changes are clean and well-tested.

@parthea parthea self-assigned this Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants