Bug: SQSMessageAttribute.binary_value raises KeyError for String attributes
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 511
- Ø Merge
- 3 T. 8 Std.
- Gemergte PRs (30 T.)
- 92
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
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationEvtl. vergeben @lechakrawarthy hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8728 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETEvtl. vergeben @coughlmao hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8727 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsEvtl. vergeben @CJstate hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
aws-powertools/powertools-lambda-python#8726 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedEvtl. vergeben @Neeraj111010 hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
aws-powertools/powertools-lambda-python#8725 · 6 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueEvtl. vergeben @sumedh-aerram hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
aws-powertools/powertools-lambda-python#8724 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aws-powertools/powertools-lambda-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
unionai-oss/pandera#2640 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
JdeRobot/RoboticsInfrastructure#843 ·
Maintainer antworten meist innerhalb von 1 Tag
-
automated endpoint-dead needs-curation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
almanac-data/climate-almanac#122 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:harness enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
evarness-ai/iris-harness#420 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
suitenumerique/find#206 ·
Maintainer antworten meist innerhalb von 2 Tagen