Bug: SQSMessageAttribute.binary_value raises KeyError for String attributes
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Expected Behaviour
SQSMessageAttribute.string_value and binary_value are typed str | None, so reading the value an attribute doesn't carry should return None.
Current Behaviour
Both properties index the dict directly (self["stringValue"], self["binaryValue"]). Lambda only sends the field that matches the attribute's type; the SQS example event in the Lambda docs has {"stringValue": "myValue", "stringListValues": [], "binaryListValues": [], "dataType": "String"} with no binaryValue. So binary_value on any String or Number attribute, and string_value on any Binary attribute, raise KeyError.
The test event tests/events/sqsEvent.json puts both stringValue and binaryValue on one attribute, which is why the existing tests don't hit this. The Pydantic SqsMsgAttributeModel already declares both fields optional.
Code snippet
from aws_lambda_powertools.utilities.data_classes import SQSEvent
event = {"Records": [{
"messageId": "1", "receiptHandle": "r", "body": "b", "attributes": {}, "md5OfBody": "m",
"eventSource": "aws:sqs", "eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:q", "awsRegion": "us-east-2",
"messageAttributes": {
"text": {"stringValue": "myValue", "stringListValues": [], "binaryListValues": [], "dataType": "String"},
},
}]}
record = next(SQSEvent(event).records)
record.message_attributes["text"].binary_value # KeyError: 'binaryValue'
Steps to Reproduce
- Send an SQS message with a String message attribute to a Lambda function.
- Read
binary_valueon that attribute (orstring_valueon a Binary one). KeyErroris raised instead ofNone.
Possible Solution
Use self.get(...) in both properties. I can open a PR.
Powertools for AWS Lambda (Python) version
latest (develop, 3.38.0)
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
No response
- Lenguaje dominante
- Python
- Estrellas
- 3.3k
- Forks
- 511
- Merge medio
- 3 d 4 h
- PR fusionados (30 d)
- 98
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
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationPosiblemente ocupada @lechakrawarthy la tomó hace 2 días. Abiertobug good first issue help wanted idempotency
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
aws-powertools/powertools-lambda-python#8728 · 4 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETPosiblemente ocupada @coughlmao la tomó hace 2 días. Abiertobug good first issue help wanted idempotency
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
aws-powertools/powertools-lambda-python#8727 · 4 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsPosiblemente ocupada @CJstate la tomó hace 2 días. Abiertobug good first issue help wanted idempotency
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
aws-powertools/powertools-lambda-python#8726 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedPosiblemente ocupada @Neeraj111010 la tomó hace 2 días. Abiertobug good first issue help wanted idempotency
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
aws-powertools/powertools-lambda-python#8725 · 6 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valuePosiblemente ocupada @sumedh-aerram la tomó hace 2 días. Abiertobug good first issue help wanted idempotency
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
aws-powertools/powertools-lambda-python#8724 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de aws-powertools/powertools-lambda-python
Issues similares
-
Paraxial.trace returns NaN for an object at infinity when the entrance pupil is at the first surfaceAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
enhancement ios launcher
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yamlAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
apache/datafusion#27059 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
loteran/Arctis-Sound-Manager#368 ·
Los mantenedores suelen responder en 1 día
-
feed submission
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MobilityData/mobility-database-catalogs#1787 ·
Los mantenedores suelen responder en 2 días