aws-powertools / powertools-lambda-python

A developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/python/latest/
MIT No Attribution
2.71k stars 376 forks source link

Bug: v2.40.0 undocumented breaking change in Router #4650

Closed karvetskiy closed 2 days ago

karvetskiy commented 3 days ago

Expected Behaviour

In out code we accessed current_event directly from Router class befor 2.40.0

Current Behaviour

In 2.40.0 version current_event available in AppSyncResolver only

Code snippet

from aws_lambda_powertools.event_handler import AppSyncResolver
from aws_lambda_powertools.event_handler.appsync import Router

user_router = Router()

@user_router.resolver(field_name="user")
def get_user() -> dict:
    return service.get_user_by_id(user_id=user_router.current_event.identity.sub)

app = AppSyncResolver()
app.include_router(user_router)

Possible Solution

No response

Steps to Reproduce

call current_event attribute from Router class

Powertools for AWS Lambda (Python) version

2.40.0

AWS Lambda function runtime

3.12

Packaging format used

Lambda Layers

Debugging logs

No response

boring-cyborg[bot] commented 3 days ago

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 commented 3 days ago

Checking now.

leandrodamascena commented 3 days ago

Hi @karvetskiy, thanks for opening this issue and reporting this bug. Our tests didn't catch accessing current_event using the Router object directly and because of this we have this breaking change in this release, sorry about that. I'm working to fix and will release a new version in a few minutes.

Thanks

leandrodamascena commented 2 days ago

Hey @karvetskiy! If I publish a pre-release on Pypi, can you test if the issue is resolved in your environment before we release a new patch release? Thanks

karvetskiy commented 2 days ago

Hey @leandrodamascena! Just checked alpha version, still can't access current_event. Looks like new Router class in event_handler.graphql_appsync.router inhered from wrong implementation of BaseRouter class. It has different implementation in v2.39.1 (see code)

heitorlessa commented 2 days ago

he hasn't published yet, will ping you shortly @karvetskiy

heitorlessa commented 2 days ago

PR incoming, we've been wrestling with static typing and additional tests to be quadruple sure this would work on areas we were missing tests too.

Once we merge and publish the alpha release we ping you

heitorlessa commented 2 days ago

kicked off pre-release (should be in PyPi in ~6 minutes or so).. https://github.com/aws-powertools/powertools-lambda-python/actions/runs/9712027684

leandrodamascena commented 2 days ago

Hey @karvetskiy! alpha release is available. Can you test pls?

https://pypi.org/project/aws-lambda-powertools/2.40.1a1/

github-actions[bot] commented 2 days ago

This is now released under 2.40.1 version!