Repository navigation
feat(datastore): add x-goog-is-transaction routing header #18848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikhilchowdary
wants to merge
1
commit into
googleapis:main
Choose a base branch
from
nikhilchowdary:feat/datastore-is-transaction-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ def _request( | |
| database, | ||
| retry=None, | ||
| timeout=None, | ||
| metadata=None, | ||
| ): | ||
| """Make a request over the Http transport to the Cloud Datastore API. | ||
|
|
||
|
|
@@ -104,6 +105,9 @@ def _request( | |
| "User-Agent": user_agent, | ||
| connection_module.CLIENT_INFO_HEADER: user_agent, | ||
| } | ||
| if metadata: | ||
| for k, v in metadata: | ||
| headers[k] = v | ||
| _update_headers(headers, project, database) | ||
| api_url = build_api_url(project, method, base_url) | ||
|
|
||
|
|
@@ -143,6 +147,7 @@ def _rpc( | |
| database, | ||
| retry=None, | ||
| timeout=None, | ||
| metadata=None, | ||
| ): | ||
| """Make a protobuf RPC request. | ||
|
|
||
|
|
@@ -185,7 +190,7 @@ def _rpc( | |
| req_data = request_pb._pb.SerializeToString() | ||
| kwargs = _make_retry_timeout_kwargs(retry, timeout) | ||
| response = _request( | ||
| http, project, method, req_data, base_url, client_info, database, **kwargs | ||
| http, project, method, req_data, base_url, client_info, database, metadata=metadata, **kwargs | ||
| ) | ||
| return response_pb_cls.deserialize(response) | ||
|
|
||
|
|
@@ -226,7 +231,7 @@ class HTTPDatastoreAPI(object): | |
| def __init__(self, client): | ||
| self.client = client | ||
|
|
||
| def lookup(self, request, retry=None, timeout=None): | ||
| def lookup(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``lookup`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.LookupRequest` or dict | ||
|
|
@@ -256,10 +261,9 @@ def lookup(self, request, retry=None, timeout=None): | |
| _datastore_pb2.LookupResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| def run_query(self, request, retry=None, timeout=None): | ||
| def run_query(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``runQuery`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.BeginTransactionRequest` or dict | ||
|
|
@@ -289,10 +293,9 @@ def run_query(self, request, retry=None, timeout=None): | |
| _datastore_pb2.RunQueryResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def run_aggregation_query(self, request, retry=None, timeout=None): | ||
| def run_aggregation_query(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``runAggregationQuery`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.BeginTransactionRequest` or dict | ||
|
|
@@ -324,10 +327,9 @@ def run_aggregation_query(self, request, retry=None, timeout=None): | |
| _datastore_pb2.RunAggregationQueryResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def begin_transaction(self, request, retry=None, timeout=None): | ||
| def begin_transaction(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``beginTransaction`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.BeginTransactionRequest` or dict | ||
|
|
@@ -357,10 +359,9 @@ def begin_transaction(self, request, retry=None, timeout=None): | |
| _datastore_pb2.BeginTransactionResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def commit(self, request, retry=None, timeout=None): | ||
| def commit(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``commit`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.CommitRequest` or dict | ||
|
|
@@ -390,10 +391,9 @@ def commit(self, request, retry=None, timeout=None): | |
| _datastore_pb2.CommitResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def rollback(self, request, retry=None, timeout=None): | ||
| def rollback(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform a ``rollback`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.RollbackRequest` or dict | ||
|
|
@@ -423,10 +423,9 @@ def rollback(self, request, retry=None, timeout=None): | |
| _datastore_pb2.RollbackResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def allocate_ids(self, request, retry=None, timeout=None): | ||
| def allocate_ids(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform an ``allocateIds`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.AllocateIdsRequest` or dict | ||
|
|
@@ -456,10 +455,9 @@ def allocate_ids(self, request, retry=None, timeout=None): | |
| _datastore_pb2.AllocateIdsResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
| def reserve_ids(self, request, retry=None, timeout=None): | ||
| def reserve_ids(self, request, retry=None, timeout=None, metadata=None): | ||
| """Perform an ``reserveIds`` request. | ||
|
|
||
| :type request: :class:`_datastore_pb2.ReserveIdsRequest` or dict | ||
|
|
@@ -489,8 +487,7 @@ def reserve_ids(self, request, retry=None, timeout=None): | |
| _datastore_pb2.ReserveIdsResponse, | ||
| database_id, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| timeout=timeout, metadata=metadata) | ||
|
|
||
|
|
||
| def _update_headers(headers, project_id, database_id=None): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Using a
for k, v in metadataloop to unpackmetadatawill raise aValueErrorifmetadatais passed as a dictionary (since iterating over a dict yields only its keys).Using
headers.update(metadata)is more robust and idiomatic, asdict.update()natively supports both dictionaries and iterables of key-value pairs (like tuples of tuples).