Repository navigation
fix(abstractions): safely handle missing values and normalize return in HeadersCollection.remove_value - #839
Merged
Vincent Biret (baywet) merged 2 commits intoOct 29, 2026
Conversation
…return in remove_value
…nd return semantics
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the header-value removal changes.
No open issues 🎉
What changed in this PR
This PR makes header-value removal safer in Kiota’s abstractions layer and clarifies its return semantics.
Changes:
- Returns
Falsewhen a value is absent instead of raisingKeyError. - Returns
Trueafter removing a header’s final value, while preserving the remaining-set return for partial removal. - Updates return-value documentation and adds regression coverage for missing values, case-insensitive header names, and removal results.
| File | Description |
|---|---|
packages/abstractions/tests/test_request_header.py |
Adds and strengthens assertions for removal behavior and return values. |
packages/abstractions/kiota_abstractions/headers_collection.py |
Safely handles absent values, fixes final-value removal results, and documents return types. |
Review effort: Balanced
Vincent Biret (baywet)
approved these changes
Oct 29, 2026
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
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.



Description
In
HeadersCollection.remove_value, callingremove_valuewith a value not present in an existing header previously caused an unhandledKeyErrorexception becauseset.remove(...)was invoked directly without verifying value membership. In contrast, callingremove_valueon a non-existent header gracefully returnedFalse.Additionally, when removing the final remaining value of a header,
remove_valuepreviously returnedset(), which evaluates toFalsein Python boolean contexts (bool(set()) == False), giving callers a false-negative status even though removal succeeded and the header was popped.This PR addresses both issues:
header_value in valuesbefore removing; returnsFalseif the value is not present, avoiding unhandledKeyErrorexceptions.Truewhen the value was removed and no values remain in the header (cleaning up the key from the internal mapping), returns the remainingset[str]when other values remain, and returnsFalsewhen the header or value was not found.remove_valueandremoveto accurately reflect theirUnion[bool, set[str]]return types.Changes
packages/abstractions/kiota_abstractions/headers_collection.py:remove_valueto returnFalseifheader_value not in values.Truewhen the header is fully cleared and removed after removing its last value.remove_valueandremove.packages/abstractions/tests/test_request_header.py:Falsewithout raisingKeyError.Testing
pytest packages/abstractions: 194/194 passed.pylint kiota_abstractions: rated 10.00/10.mypy kiota_abstractions: 0 issues found across 48 source files.yapfand import sorting withisort.