Skip to content

Bug: Python 3.10 :: SQSEvent :: AttributeError: 'dict' object has no attribute 'records' #4919

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

Closed
CloutKhan opened this issue Aug 9, 2024 · 4 comments
Labels
event_sources Event Source Data Class utility not-a-bug

Comments

@CloutKhan
Copy link

Expected Behaviour

events.records can be used as the iterator over records.

Current Behaviour

AttributeError: 'dict' object has no attribute 'records'

Code snippet

from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSEvent
from aws_lambda_powertools.utilities.typing import LambdaContext

def lambda_handler(sqs_event: SQSEvent, context: LambdaContext):
    for record in event.records: # where event["Records"] does not fail.
        pass

Possible Solution

No response

Steps to Reproduce

Try to access event.records as a property on an SQSEvent instance.

Powertools for AWS Lambda (Python) version

2.42.0

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers

Debugging logs

No response

@CloutKhan CloutKhan added bug Something isn't working triage Pending triage from maintainers labels Aug 9, 2024
Copy link

boring-cyborg bot commented Aug 9, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena
Copy link
Contributor

Hi @CloutKhan! Thanks for opening this issue. This is actually not a bug, what is happening here is because you are using SQSEvent in your function signature but you are not using the @event_source decorator, so we are not able to convert your dict to an object. Check if this works with the code below:

from aws_lambda_powertools.utilities.data_classes import event_source, SQSEvent
from aws_lambda_powertools.utilities.typing import LambdaContext

@event_source(data_class=SQSEvent)
def lambda_handler(event: SQSEvent, context: LambdaContext):
    for record in event.records: # where event["Records"] does not fail.
        pass

thanks

@leandrodamascena leandrodamascena moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Aug 9, 2024
@leandrodamascena leandrodamascena added not-a-bug event_sources Event Source Data Class utility and removed bug Something isn't working triage Pending triage from maintainers labels Aug 9, 2024
@leandrodamascena
Copy link
Contributor

Please reopen this issue if you need any further support @CloutKhan!

Closing as not a bug.

@github-project-automation github-project-automation bot moved this from Pending customer to Coming soon in Powertools for AWS Lambda (Python) Aug 11, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@leandrodamascena leandrodamascena moved this from Coming soon to Closed in Powertools for AWS Lambda (Python) Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event_sources Event Source Data Class utility not-a-bug
Projects
Development

No branches or pull requests

2 participants