Bug: SQSMessageAttribute.binary_value raises KeyError for String attributes
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 3.3k
- Fork
- 511
- Merge trung bình
- 3 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 93
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationCó thể đã có người làm @lechakrawarthy đã nhận hôm nay. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8728 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8727 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
aws-powertools/powertools-lambda-python#8726 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
aws-powertools/powertools-lambda-python#8725 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueCó thể đã có người làm @sumedh-aerram đã nhận hôm nay. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
aws-powertools/powertools-lambda-python#8724 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của aws-powertools/powertools-lambda-python
Issue tương tự
-
PluginProvider.storeInstance races and clobbers the dedup cache for concurrent loadsCó thể đã có người làm @Wilson0511 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
community documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
kagent-dev/kagent#3462 ·
Maintainer thường phản hồi trong vòng 1 ngày