Skip to content

fix(data_classes): return None for the SQS attribute value an attribute does not carry - #8713

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
anishmehta24:fix/sqs-message-attribute-missing-value
Nov 4, 2026
Merged

leandrodamascena merged 2 commits into
aws-powertools:developfrom
anishmehta24:fix/sqs-message-attribute-missing-value

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Issue number: closes #8712

Summary

Changes

SQSMessageAttribute.string_value and binary_value are typed str | None but indexed the dict directly. Lambda only includes the field matching the attribute's type (a String attribute has no binaryValue, a Binary one no stringValue), so reading the other one raised KeyError. Both now use self.get(...) and return None, which matches their type hints and the Pydantic SqsMsgAttributeModel; the docstrings say when the value is None.

Added test_sqs_message_attribute_with_only_one_value in tests/unit/data_classes/required_dependencies/test_sqs_event.py with a String and a Binary attribute shaped like the Lambda docs example; it fails on develop with KeyError: 'binaryValue'. The data classes and batch tests pass.

User experience

Before: record.message_attributes["text"].binary_value on a String attribute raises KeyError. After: it returns None.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@anishmehta24
anishmehta24 requested a review from a team as a code owner October 30, 2026 16:58
@anishmehta24
anishmehta24 requested a review from hjgraca October 30, 2026 16:58
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 30, 2026
@boring-cyborg boring-cyborg Bot added the tests label Oct 30, 2026
@leandrodamascena leandrodamascena added this to the 3.40.0 milestone Oct 30, 2026

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @anishmehta24, confirmed with a real event: I sent a message with String, Number and Binary attributes through a queue to a function and Lambda delivers only the field matching the type, so binary_value on the String one raises KeyError on develop and returns None with your change, same as the Pydantic model already does.

I'm approving now. This goes out in 3.40.0, so it will sit here for a while before I merge it. No rebase needed in the meantime, and you'll be credited in the release notes.

@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.02%. Comparing base (d28d84a) to head (95b6258).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8713   +/-   ##
========================================
  Coverage    97.02%   97.02%           
========================================
  Files          321      321           
  Lines        16443    16443           
  Branches      1487     1487           
========================================
  Hits         15954    15954           
  Misses         349      349           
  Partials       140      140           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit 8074a54 into aws-powertools:develop Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SQSMessageAttribute.binary_value raises KeyError for String attributes

2 participants