Skip to content

fix(data_sources): ensure correct types on SQSMessageAttributes #3898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aws_lambda_powertools/utilities/data_classes/sqs_event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import cached_property
from typing import Any, Dict, Iterator, Optional, Type, TypeVar
from typing import Any, Dict, ItemsView, Iterator, Optional, Type, TypeVar

from aws_lambda_powertools.utilities.data_classes import S3Event
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
Expand Down Expand Up @@ -82,6 +82,9 @@ def __getitem__(self, key: str) -> Optional[SQSMessageAttribute]: # type: ignor
item = super().get(key)
return None if item is None else SQSMessageAttribute(item) # type: ignore

def items(self) -> ItemsView[str, SQSMessageAttribute]: # type: ignore
return {k: SQSMessageAttribute(v) for k, v in super().items()}.items() # type: ignore


class SQSRecord(DictWrapper):
"""An Amazon SQS message"""
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/data_classes/test_sqs_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from aws_lambda_powertools.utilities.data_classes import S3Event, SQSEvent
from aws_lambda_powertools.utilities.data_classes.sns_event import SNSMessage
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSMessageAttributes
from tests.functional.utils import load_event


Expand Down Expand Up @@ -132,3 +133,10 @@ def test_decode_nested_sns_event():
raw_message = json.loads(raw_body["Message"])
assert message["message"] == raw_message["message"]
assert message["username"] == raw_message["username"]


def test_sqs_event_typing():
attributes = SQSMessageAttributes({"key": {"stringValue": "value", "dataType": "String"}})

# This assertion compares the return from .items() to the return of __getitem__
assert list(attributes.items())[0][1] == attributes["key"]