Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mapping
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先在数据类工具中定位 CaseInsensitiveDict,并结合这里描述的字典比较行为阅读其 __eq__ 实现。使用提供的代码片段复现不一致,然后检查或添加针对 == 和 != 的测试,包括 APIGatewayProxyEvent.headers 的情况。当不等于始终给出与等于相反的结果,且针对性测试通过时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Expected Behaviour
!= is the opposite of ==. If event.headers == {"Content-Type": "application/json"} is True, then event.headers != {"Content-Type": "application/json"} is False.
Current Behaviour
Both comparisons return True. CaseInsensitiveDict overrides __eq__ (lowercasing the other mapping's keys) but not __ne__. dict.__ne__ does not call __eq__; it compares the raw lowercased keys with the other mapping's original keys, so any mapping with non-lowercase keys compares as different.
Code snippet
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
from aws_lambda_powertools.utilities.data_classes.common import CaseInsensitiveDict
headers = CaseInsensitiveDict({"Content-Type": "application/json"})
print(headers == {"Content-Type": "application/json"}) # True
print(headers != {"Content-Type": "application/json"}) # True <- expected False
event = APIGatewayProxyEvent({"headers": {"Content-Type": "application/json"}})
print(event.headers != {"Content-Type": "application/json"}) # True <- expected False
Possible Solution
Define __ne__ in terms of __eq__:
def __ne__(self, other):
result = self.__eq__(other)
return result if result is NotImplemented else not result
I have this ready on a branch with tests (parametrized ==/!= cases for mixed-case, lowercase and CaseInsensitiveDict operands, non-equal mappings and a non-mapping, plus an event.headers case through APIGatewayProxyEvent): https://github.com/khaledix3/powertools-lambda-python/tree/fix/case-insensitive-dict-ne
Two of the new tests fail on develop and all pass with the fix; the rest of tests/unit, tests/functional/event_handler and tests/functional/validator give the same results before and after. Happy to open the PR once this is triaged.
I used an AI assistant (Claude) to find and fix this, and ran the snippet and tests myself.
Steps to Reproduce
- Run the snippet above on
develop(0bbc252) or the latest release. - Observe that
==and!=both returnTruefor the same mapping.
Did you run the reproduction yourself?
Yes, I ran it and saw the failure
Powertools for AWS Lambda (Python) version
latest (3.41.0, also develop 0bbc252)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
- 主要语言
- Python
- 星标
- 3.3k
- 派生
- 511
- 平均合并
- 2 天 23 小时
- 30 天内合并 PR
- 50
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws-powertools/powertools-lambda-python 的其他 Issue
-
Docs: child Logger without a parent uses the root log level since #8842可能已有人在做 @rdxrahul12 今天认领。 未关闭documentation triage
难度 1/5 1-3 小时 新手友好度 85/100
aws-powertools/powertools-lambda-python#8935 · 3 条评论 ·
维护者通常 1 天内回复
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responses可能已有人在做 @saquibjawedbit 于 4 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
aws-powertools/powertools-lambda-python#8921 · 2 条评论 ·
维护者通常 1 天内回复
-
Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopes可能已有人在做 @0x5t4l1n 今天认领。 未关闭bug triage
难度 2/5 1-3 小时 新手友好度 88/100
aws-powertools/powertools-lambda-python#8918 · 2 条评论 ·
维护者通常 1 天内回复
-
Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQS可能已有人在做 @hyeonsang010716 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
aws-powertools/powertools-lambda-python#8913 ·
维护者通常 1 天内回复
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metrics可能已有人在做 @hyeonsang010716 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
aws-powertools/powertools-lambda-python#8911 ·
维护者通常 1 天内回复
查看 aws-powertools/powertools-lambda-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
litestar-org/sqlspec#946 ·
维护者通常 1 天内回复
-
area:cli area:docs Platform vdr
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA-NeMo/Gym#7192 ·
维护者通常 2 天内回复
-
SofyaBot未关闭
难度 2/5 1-3 小时 新手友好度 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 78/100
hesreallyhim/awesome-claude-code#3821 · 1 条评论 ·
-
bug good first issue help wanted level 1 wocs
难度 2/5 1-3 小时 新手友好度 92/100
GianlucaBave/murmury#169 ·
维护者通常 1 天内回复