Skip to content

feat(datastore): add x-goog-is-transaction routing header - #18848

Open
nikhilchowdary wants to merge 1 commit into
googleapis:mainfrom
nikhilchowdary:feat/datastore-is-transaction-header
Open

nikhilchowdary wants to merge 1 commit into
googleapis:mainfrom
nikhilchowdary:feat/datastore-is-transaction-header

Conversation

@nikhilchowdary

@nikhilchowdary nikhilchowdary commented Oct 25, 2026 •

Copy link
Copy Markdown

Add x-goog-is-transaction routing header in python SDK to differentiate transactional requests and non-transactional requests from each other. Having a routing header for transactions helps in routing grpc requests at GFE.

This commit attaches the x-goog-is-transaction routing header to all RPCs

  • Set to true for transactional RPCs
    -- beginTransaction
    -- rollback
    -- transactional commit
    -- transactional lookup
    -- transactional runQuery
    -- transactional runAggregationQuery.

  • Set to false for non transactional RPCs
    -- allocateIds
    -- non transactional commit
    -- non transactional lookup
    -- non transactional runQuery
    -- non transactional runAggregationQuery.

cc: @MarkDuckworth

This commit attaches the `x-goog-is-transaction` routing metadata header to all RPCs in `google-cloud-datastore` (both gRPC and HTTP transports):
- Set to `true` for transactional RPCs (`begin_transaction`, `rollback`, and transactional `commit`, `lookup`, `run_query`, `run_aggregation_query`).
- Set to `false` for non-transactional RPCs (`allocate_ids`, `reserve_ids`, and non-transactional `commit`, `lookup`, `run_query`, `run_aggregation_query`).
@nikhilchowdary
nikhilchowdary requested a review from a team as a code owner October 25, 2026 07:04

@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 introduces transaction metadata tracking across Google Cloud Datastore client requests by adding a 'metadata' parameter to propagate the 'x-goog-is-transaction' header. This header is set dynamically depending on whether the request is transactional or non-transactional. Feedback on these changes includes a recommendation to use 'headers.update(metadata)' instead of a 'for' loop to avoid potential 'ValueError' exceptions when 'metadata' is a dictionary, as well as a suggestion to format multi-line function calls in accordance with PEP 8.

Comment on lines +108 to +110
if metadata:
for k, v in metadata:
headers[k] = v

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.

medium

Using a for k, v in metadata loop to unpack metadata will raise a ValueError if metadata is passed as a dictionary (since iterating over a dict yields only its keys).

Using headers.update(metadata) is more robust and idiomatic, as dict.update() natively supports both dictionaries and iterables of key-value pairs (like tuples of tuples).

    if metadata:
        headers.update(metadata)

retry=retry,
timeout=timeout,
)
timeout=timeout, metadata=metadata)

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.

medium

To adhere to PEP 8 style guidelines for multi-line function calls, each argument should be on its own line, and the closing parenthesis should be aligned with the start of the statement.

Suggested change
timeout=timeout, metadata=metadata)
timeout=timeout,
metadata=metadata,
)

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.

1 participant