Skip to content

Added Response Headers to Control Plane Operations #41742

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
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

andrewmathew1
Copy link
Contributor

This PR introduces a way to get response headers for given control plane operations on containers and databases. This is availble for both the async and sync client. Similar to #35791 for response headers at the item level.

@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 20:03
@andrewmathew1 andrewmathew1 requested a review from a team as a code owner June 24, 2025 20:03
Copilot

This comment was marked as outdated.

@andrewmathew1 andrewmathew1 requested a review from Copilot June 24, 2025 20:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds support for retrieving response headers for control plane operations (databases and containers) on the Cosmos service, for both synchronous and asynchronous clients.

  • Introduces new test cases to verify that response headers are returned for various operations.
  • Adds a new get_response_headers method and initializes _response_headers in the Database and Container classes (including their async counterparts).

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/tests/test_cosmos_responses_async.py Added async tests for response headers on database and container operations.
sdk/cosmos/azure-cosmos/tests/test_cosmos_responses.py Added sync tests for response headers on database and container operations.
sdk/cosmos/azure-cosmos/azure/cosmos/database.py Added _response_headers initialization and get_response_headers method.
sdk/cosmos/azure-cosmos/azure/cosmos/container.py Added _response_headers initialization and get_response_headers method.
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_database.py Added _response_headers initialization and get_response_headers method for async client.
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py Added _response_headers initialization and get_response_headers method for async client.

@@ -94,6 +94,7 @@ def __init__(
self.id = id
self.database_link: str = "dbs/{}".format(self.id)
self._properties: Optional[Dict[str, Any]] = properties
self._response_headers = properties
Copy link
Preview

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'properties' is None, calling get_response_headers() may raise an AttributeError when attempting to use .copy(). Consider initializing _response_headers to an empty dictionary (e.g., properties or {} if properties is None).

Suggested change
self._response_headers = properties
self._response_headers = properties if properties is not None else {}

Copilot uses AI. Check for mistakes.

@@ -104,6 +104,7 @@ def __init__(
self.client_connection = client_connection
self._is_system_key: Optional[bool] = None
self._scripts: Optional[ScriptsProxy] = None
self._response_headers = properties
Copy link
Preview

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'properties' is None, calling get_response_headers() could lead to an error since .copy() would not be available. Consider defaulting _response_headers to {} when properties is None.

Suggested change
self._response_headers = properties
self._response_headers = properties if properties is not None else {}

Copilot uses AI. Check for mistakes.

@@ -100,6 +100,7 @@ def __init__(
self.id = id
self.database_link = "dbs/{}".format(self.id)
self._properties = properties
self._response_headers = properties
Copy link
Preview

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that _response_headers is always a dictionary. If properties is None, using .copy() in get_response_headers() will fail; consider initializing with {} as a fallback.

Suggested change
self._response_headers = properties
self._response_headers = properties if properties is not None else {}

Copilot uses AI. Check for mistakes.

@@ -93,6 +93,7 @@ def __init__(
self.container_link = "{}/colls/{}".format(database_link, self.id)
self._is_system_key: Optional[bool] = None
self._scripts: Optional[ScriptsProxy] = None
self._response_headers = properties
Copy link
Preview

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'properties' is passed as None, calling .copy() in get_response_headers() will result in an error. Consider initializing _response_headers to {} when properties is None.

Suggested change
self._response_headers = properties
self._response_headers = properties if properties is not None else {}

Copilot uses AI. Check for mistakes.

Copy link

github-actions bot commented Jun 24, 2025

API Change Check

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

azure-cosmos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant