Skip to content

fix(data_classes): make CaseInsensitiveDict inequality consistent - #8960

Open
CJstate wants to merge 1 commit into
aws-powertools:developfrom
CJstate:fix/case-insensitive-dict-ne
Open

CJstate wants to merge 1 commit into
aws-powertools:developfrom
CJstate:fix/case-insensitive-dict-ne

Conversation

@CJstate

@CJstate CJstate commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CaseInsensitiveDict overrides __eq__ to normalize key casing, but it did not override __ne__. As a result, event headers could compare equal and unequal to the same mapping at once whenever the mapping keys differed in case, breaking != checks in handlers.

This adds __ne__ that delegates to __eq__, so equality and inequality always agree. The regression test asserts that a header mapping with differently cased keys is not reported as unequal.

closes #8948

Verification

Focused pytest before the source fix (exact failing line):

tests/unit/data_classes/required_dependencies/test_common.py::test_case_insensitive_dict_ne_matches_eq_semantics FAILED [100%]
E       AssertionError: assert not {'content-type': 'application/json'} != {'Content-Type': 'application/json'}

tests\unit\data_classes\required_dependencies\test_common.py:66: AssertionError
========================= 1 failed, 5 passed in 3.65s =========================

After the source fix:

tests/unit/data_classes/required_dependencies/test_common.py::test_case_insensitive_dict_ne_matches_eq_semantics PASSED [100%]
============================== 6 passed in 1.48s ==============================

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

CaseInsensitiveDict defined case-insensitive equality but inherited dict inequality, so a mapping with differently cased keys compared equal and unequal at the same time. Implement __ne__ in terms of __eq__ so both operators agree.

Signed-off-by: CJstate <142857225+CJstate@users.noreply.github.com>
@CJstate
CJstate requested a review from a team as a code owner December 5, 2026 11:07
@boring-cyborg boring-cyborg Bot added the tests label Dec 5, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 5, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mapping

1 participant