Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mapping
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 76/100
Rechercherichtung
Beginne damit, CaseInsensitiveDict in den Dienstprogrammen für Datenklassen zu finden, und lies die __eq__-Implementierung zusammen mit dem hier beschriebenen Verhalten beim Vergleich von Dictionaries. Reproduziere die Abweichung mit dem bereitgestellten Snippet und prüfe oder ergänze anschließend gezielte Tests für == und !=, einschließlich des Falls APIGatewayProxyEvent.headers. Fertig ist die Aufgabe, wenn Ungleichheit konsistent das Gegenteil des Ergebnisses von Gleichheit liefert und die gezielten Tests bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 511
- Ø Merge
- 2 T. 23 Std.
- Gemergte PRs (30 T.)
- 50
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aws-powertools/powertools-lambda-python
-
Docs: child Logger without a parent uses the root log level since #8842Evtl. vergeben @rdxrahul12 hat das heute übernommen. Offendocumentation triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8935 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responsesEvtl. vergeben @saquibjawedbit hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8921 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopesEvtl. vergeben @0x5t4l1n hat das heute übernommen. Offenbug triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
aws-powertools/powertools-lambda-python#8918 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQSEvtl. vergeben @hyeonsang010716 hat das vor 7 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
aws-powertools/powertools-lambda-python#8913 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metricsEvtl. vergeben @hyeonsang010716 hat das vor 7 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
aws-powertools/powertools-lambda-python#8911 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aws-powertools/powertools-lambda-python
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
litestar-org/sqlspec#946 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:cli area:docs Platform vdr
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
NVIDIA-NeMo/Gym#7192 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
SofyaBotOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarOffenresource-submission validation-passed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
hesreallyhim/awesome-claude-code#3821 · 1 Kommentar ·
-
bug good first issue help wanted level 1 wocs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
GianlucaBave/murmury#169 ·
Maintainer antworten meist innerhalb von 1 Tag