Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mapping
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
Empieza por localizar CaseInsensitiveDict en las utilidades de clases de datos y leer su implementación de __eq__ junto con el comportamiento de comparación de diccionarios descrito aquí. Reproduce la discrepancia con el fragmento proporcionado y después comprueba o añade pruebas específicas para == y !=, incluido el caso de APIGatewayProxyEvent.headers. La tarea se considera terminada cuando la desigualdad da de forma coherente el resultado opuesto al de la igualdad y las pruebas específicas pasan.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 3.3k
- Forks
- 511
- Merge medio
- 2 d 23 h
- PR fusionados (30 d)
- 50
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de aws-powertools/powertools-lambda-python
-
Docs: child Logger without a parent uses the root log level since #8842Posiblemente ocupada @rdxrahul12 la tomó hoy. Abiertodocumentation triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
aws-powertools/powertools-lambda-python#8935 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responsesPosiblemente ocupada @saquibjawedbit la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
aws-powertools/powertools-lambda-python#8921 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopesPosiblemente ocupada @0x5t4l1n la tomó hoy. Abiertobug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
aws-powertools/powertools-lambda-python#8918 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQSPosiblemente ocupada @hyeonsang010716 la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
aws-powertools/powertools-lambda-python#8913 ·
Los mantenedores suelen responder en 1 día
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metricsPosiblemente ocupada @hyeonsang010716 la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
aws-powertools/powertools-lambda-python#8911 ·
Los mantenedores suelen responder en 1 día
Todos los issues de aws-powertools/powertools-lambda-python
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
litestar-org/sqlspec#946 ·
Los mantenedores suelen responder en 1 día
-
area:cli area:docs Platform vdr
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA-NeMo/Gym#7192 ·
Los mantenedores suelen responder en 2 días
-
SofyaBotAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
hesreallyhim/awesome-claude-code#3821 · 1 comentario ·
-
bug good first issue help wanted level 1 wocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
GianlucaBave/murmury#169 ·
Los mantenedores suelen responder en 1 día