Skip to content

Conversation

@Nikhil172913832
Copy link

Fixes #43662

Ensure parameters=None is treated the same as omitting parameters, preventing TypeError in HTTP request layer.

Description

This PR fixes a TypeError that occurs when parameters=None is explicitly passed to container.query_items() in the Cosmos DB SDK.

Problem:
When users explicitly pass parameters=None to query_items(), the SDK would create a query dictionary with a None parameters value, which would then be passed down to the HTTP request layer causing a TypeError: Session.request() got an unexpected keyword argument 'parameters'.

Solution:
Modified the query building logic in both sync and async container implementations to check if parameters has a non-None value before including it in the query structure. Now parameters=None is treated identically to omitting the parameter entirely, returning a simple query string instead of a dictionary with None values.

Changes:

  • sdk/cosmos/azure-cosmos/azure/cosmos/container.py: Updated query building logic (lines 936-941)
  • sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py: Updated async query building logic (lines 824-829)

Impact:

  • Fixes regression from version 4.9.0
  • No breaking changes - all existing usage patterns remain unchanged
  • Only affects the specific case where parameters=None is explicitly passed

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Fixes Azure#43662

Ensure parameters=None is treated the same as omitting parameters,
preventing TypeError in HTTP request layer.
@Nikhil172913832 Nikhil172913832 requested a review from a team as a code owner October 29, 2025 07:46
Copilot AI review requested due to automatic review settings October 29, 2025 07:46
@github-actions github-actions bot added Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 29, 2025
@github-actions
Copy link

Thank you for your contribution @Nikhil172913832! We will review the pull request and get back to you soon.

@Nikhil172913832
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Contributor

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 PR refactors the query parameter handling logic in the query_items method for both synchronous and asynchronous container implementations. The change simplifies the condition for determining when to construct a parameterized query object by checking for parameter existence directly rather than using a utility function.

Key Changes:

  • Replaced utils.valid_key_value_exist(kwargs, "parameters") with a direct parameters is not None check
  • Extracted query and parameters values into intermediate variables before the conditional logic

Reviewed Changes

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

File Description
sdk/cosmos/azure-cosmos/azure/cosmos/container.py Updated query parameter handling in the synchronous query_items method
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py Updated query parameter handling in the async query_items method

@Nikhil172913832
Copy link
Author

The failing test (test_read_items_concurrency_internals) seems unrelated to the changes in this PR.
My update only affects the query_items() method when parameters=None, and doesn't modify any of the read_items or concurrency internals.
Could you please re-run the CI to confirm if this failure is transient?

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

Thanks @Nikhil172913832 for making these changes, really appreciate it. However, we cannot accept the PR without any test coverage, can you please add tests if possible or if you would like, we can take this change ourselves and add appropriate tests to it, let us know!

@Nikhil172913832
Copy link
Author

@kushagraThapar I will add the necessary test.

@Nikhil172913832
Copy link
Author

@kushagraThapar I’ve added the tests for the fix as requested. Let me know if everything looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Cosmos DB TypeError when passing "parameters=None"

2 participants