-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Cosmos] item operation response includes response headers #35791
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
Merged
Conversation
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
Collaborator
|
API change check APIView has identified API level changes in this PR and created following API reviews. |
annatisch
reviewed
Jun 11, 2024
Member
Author
|
/azp run python - cosmos - tests |
Member
|
Adding a reference to underlying Azure SDK feature issue: #32571 |
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
xinlian12
reviewed
Aug 1, 2024
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Outdated
Show resolved
Hide resolved
annatisch
reviewed
Aug 1, 2024
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Outdated
Show resolved
Hide resolved
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
annatisch
reviewed
Oct 15, 2024
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py
Outdated
Show resolved
Hide resolved
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
annatisch
approved these changes
Oct 16, 2024
This was referenced Oct 16, 2024
l0lawrence
pushed a commit
to l0lawrence/azure-sdk-for-python
that referenced
this pull request
Feb 19, 2025
* adds new response to sync point operations * Update _cosmos_response.py * addresses comments, adds query changes * added logic to deal with unpacking of actual values * pylint * async changes * Update CHANGELOG.md * samples using last_response_headers * update use of last_response_headers, sanity check on responses * add header tests * readme and oopsies * test fixes * Update sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_responses.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_responses.py Co-authored-by: Anna Tisch <[email protected]> * typing updates * pylint * mypy part1 * tests * fixes * tests * update typehint for mypy * Revert "update typehint for mypy" This reverts commit adbab3a. * mypy * Update _cosmos_client_connection.py * Update _cosmos_client_connection.py * Update _cosmos_client_connection.py * Update _cosmos_client_connection.py * Update _cosmos_client_connection_async.py * Update _cosmos_client_connection_async.py * public surface area changes * review updates * Update README.md * Update README.md * Update container.py * rename responses and update inhertiance typing * revert subtyping * missed empty dict responses * Update test_globaldb.py * simplify query_iterable header logic * revert * add subscripts to class definition * try re-adding typehint * revert * specify rtypes * Update _cosmos_client_connection.py * remove query changes * Update _cosmos_client_connection_async.py * update rtypes * pylint * revert more query stuff --------- Co-authored-by: Anna Tisch <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We do not have a good way for users to access response headers. Currently, we use a last_response_headers dictionary (map) that gets cached in the client instance, and recommend users look at headers like such:

Not only is this design not intuitive, it is not thread safe, so using it directly has no real guarantees of validity depending on what the user is trying to do. Separately, we also allow users to pass in a function/method/callable response_hook, and have recently made that functionality thread safe, but having to require users to send in a function/method/callable in order to access these headers is also less than ideal from a UX perspective. Since in Cosmos headers can be highly relevant to user cases, this PR attempts to improve the user experience.
This PR adds the ability to fetch response headers for a given operation directly from its response through a newly introduced method. The new return type can do this, while still maintaining its ability to work as previously, with
CosmosDictbehaving like a dict andCosmosListbehaving like a list.This means an operation response like this:

Would now be able to have direct knowledge into the response headers associated with it by doing this, and would be able to use that information directly:


Follow-up work




For query operations, since each request is made to one partition at once, aggregating the results of an entire query result for cross-partition scenarios is going to be a separate issue. For now, much like in the Java SDK we will collect headers on a per-page basis for pagination scenarios - and in this case the headers will be updated in the pageable object as the user goes through each of them:
and then the next page:
Issue for this item: #37932
Items in this PR: