Skip to content
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

[Cosmos] item operation response includes response headers #35791

Merged
merged 57 commits into from
Oct 16, 2024

Conversation

simorenoh
Copy link
Member

@simorenoh simorenoh commented May 28, 2024

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:
image

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 CosmosDict behaving like a dict and CosmosList behaving like a list.

This means an operation response like this:
image

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:
image
image

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:
image
image
and then the next page:
image
image

Items in this PR:

  • changes for sync client
  • changes for async client
  • query headers
  • refactoring of tests previously using last_response_headers
  • refactoring of samples previously using last_response_headers
  • CHANGELOG
  • adds additional tests for new response headers packaging

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 28, 2024

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-cosmos

@simorenoh
Copy link
Member Author

/azp run python - cosmos - tests

@annatisch
Copy link
Member

Adding a reference to underlying Azure SDK feature issue: #32571

@simorenoh simorenoh marked this pull request as ready for review June 19, 2024 16:42
@simorenoh simorenoh changed the title [Cosmos] item response includes response headers [Cosmos] item operation response includes response headers Jul 20, 2024
@simorenoh simorenoh requested a review from a team as a code owner August 1, 2024 18:55
@simorenoh
Copy link
Member Author

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh
Copy link
Member Author

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

sdk/cosmos/azure-cosmos/README.md Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/README.md Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/azure/cosmos/_query_iterable.py Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_responses.py Outdated Show resolved Hide resolved
@simorenoh
Copy link
Member Author

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh simorenoh merged commit 738d9da into Azure:main Oct 16, 2024
19 checks passed
@simorenoh simorenoh deleted the package-response-headers branch October 16, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants