Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mapping
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、データクラスのユーティリティ内で 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時間
- マージ済み PR(30日)
- 50
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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]: Dashbarオープン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 日以内に返信