Skip to content

Handle map-style query parameters with None values - #666

Open
Bart Koelman (bkoelman) wants to merge 2 commits into
microsoft:mainfrom
bkoelman:fix/map-query-parameters
Open

Handle map-style query parameters with None values#666
Bart Koelman (bkoelman) wants to merge 2 commits into
microsoft:mainfrom
bkoelman:fix/map-query-parameters

Conversation

@bkoelman

Copy link
Copy Markdown

Contributes to microsoft/kiota#3800.

Dict values used as map/dictionary query parameters (from an OpenAPI type: object with additionalProperties field) are now sanitized before being passed to StdUriTemplate. None values are silently dropped per RFC 6570 §2.3 "undefined" semantics, preventing a ValueError when StdUriTemplate tries to convert None to a string. An empty string must be set explicitly to send key=.

Adds seven test cases covering map expansion, None-value omission, empty-string inclusion, empty dicts, all-None dicts, mixed scalar+map parameters, and the set_query_string_parameters_from_raw_object() path.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution!

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Jul 23, 2026
@baywet

Copy link
Copy Markdown
Member

Bart Koelman (@bkoelman) can you fix the formatting as reported by this action run please? after that I think we'd be good to go

Copilot AI left a comment

Copy link
Copy Markdown

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 updates RequestInformation URL building to safely handle map/dictionary-style query parameters whose values include None, aligning behavior with RFC 6570 “undefined” semantics and preventing StdUriTemplate from raising when encountering None inside map expansions.

Changes:

  • Sanitize dict values passed into URI template expansion by dropping None entries and recursively sanitizing remaining values.
  • Add new unit tests covering map query expansion behavior (including omission of None values and preservation of empty strings), plus a dataclass-based set_query_string_parameters_from_raw_object() path.

Reviewed changes

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

File Description
packages/abstractions/kiota_abstractions/request_information.py Adds dict/map sanitization to omit None entries before URI template expansion.
packages/abstractions/tests/test_request_information.py Adds test coverage for RFC 6570 map-style query parameter expansion and edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/abstractions/kiota_abstractions/request_information.py
Bart Koelman (bkoelman) and others added 2 commits July 24, 2026 03:09
Dict values used as map/dictionary query parameters (from an OpenAPI
`type: object` with `additionalProperties` field) are now sanitized
before being passed to StdUriTemplate.  None values are silently dropped
per RFC 6570 §2.3 "undefined" semantics, preventing a ValueError when
StdUriTemplate tries to convert None to a string.  An empty string must
be set explicitly to send `key=`.

Adds seven test cases covering map expansion, None-value omission,
empty-string inclusion, empty dicts, all-None dicts, mixed scalar+map
parameters, and the set_query_string_parameters_from_raw_object() path.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ery parameters

Address build check feedback by fixing yapf formatting in request_information.py and isort ordering in date_utils.py. Also ignore None keys when sanitizing map query parameters.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@bkoelman

Copy link
Copy Markdown
Author

pushed fixes and rebased on latest main

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for making the changes!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +312 to +319
elif isinstance(value, dict):
# Map-style query parameter: drop None entries per RFC 6570 §2.3 "undefined"
# semantics, then normalise remaining values. StdUriTemplate raises ValueError
# when it encounters None inside a map, so we strip them here.
sanitized_value = {
str(k): self._get_sanitized_value(v)
for k, v in value.items() if k is not None and v is not None
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress 🚧

Development

Successfully merging this pull request may close these issues.

3 participants