Skip to content

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

Closed

Description

@leandrodamascena

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

Activity

  1. rubenfonseca commented on Nov 22, 2023

    @rubenfonseca
    Contributor

    Working at this now

  2. moved this from Backlog to Working on it in Powertools for AWS Lambda (Python)on Nov 22, 2023
  3. github-actions commented on Nov 22, 2023

    @github-actions
    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.

  4. github-actions commented on Nov 23, 2023

    @github-actions
    Contributor

    This is now released under 2.28.0 version!

  5. moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python)on Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions