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 天內回覆