Skip to content
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

Bug: Pydantic is being imported when using Event Handler without validation #3370

Closed
leandrodamascena opened this issue Nov 20, 2023 · 3 comments · Fixed by #3397
Closed
Assignees
Labels
bug Something isn't working event_handlers

Comments

@leandrodamascena
Copy link
Contributor

Expected Behaviour

I'm using ApiGatewayResolver without enabling validation and it shouldn't import Pydantic. Even if a customer has Pydantic installed, they should not import Pydantic without explicitly enabling validation: app = ApiGatewayResolver(enable_validation=True)

Current Behaviour

Profiling the application with tuna, I can see Pydantic being imported:

image

Code snippet

from aws_lambda_powertools.event_handler import ApiGatewayResolver

app = ApiGatewayResolver(enable_validation=False)

def lambda_handler(event, context):
    return app.resolve(event, context)


requirements.txt
aws-lambda-powertools==2.27.0
aws-xray-sdk==2.12.1
botocore==1.32.3
fastjsonschema==2.19.0
jmespath==1.0.1
pydantic==1.10.13
python-dateutil==2.8.2
six==1.16.0
tuna==0.5.11
typing_extensions==4.8.0
urllib3==2.0.7
wrapt==1.16.0

Possible Solution

Move these imports to an standalone file or import them only when enable_validation is True.

Steps to Reproduce

1 - Create a file
2 - pip install aws-lambda-powertools[all] tuna
3 - Use the code snippet provided
4 - python -X importtime test.py 2> prof1.log
5 - tuna prof1.log

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.11

Packaging format used

PyPi

Debugging logs

No response

@leandrodamascena leandrodamascena added bug Something isn't working triage Pending triage from maintainers labels Nov 20, 2023
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Nov 21, 2023
@heitorlessa heitorlessa moved this from Triage to Backlog in Powertools for AWS Lambda (Python) Nov 21, 2023
@rubenfonseca
Copy link
Contributor

Working at this now

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.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Nov 22, 2023
Copy link
Contributor

This is now released under 2.28.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Nov 23, 2023
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

3 participants