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.82k stars 392 forks source link

Bug: pydantic imports from aws_lambda_powertools.utilities.parser.pydantic no longer available #5249

Open RyanFrench opened 1 day ago

RyanFrench commented 1 day ago

Expected Behaviour

As per the documentation FAQ I would expect to be able to import X from pydantic to include types such as EmailStr

Current Behaviour

Currently in 3.0.0 we are unable to import pydantic types via the parser.

Code snippet

from aws_lambda_powertools.utilities.parser.pydantic import EmailStr

Possible Solution

Update documentation to include the recommended way to import X from pydantic, or implement the feature that was available in 2.X.

Steps to Reproduce

Try and import a pydantic type from aws_lambda_powertools.utilities.parser.pydantic, which no longer exists.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.11

Packaging format used

PyPi

Debugging logs

No response

boring-cyborg[bot] commented 1 day 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 1 day ago

Hey @RyanFrench, thanks for opening this issue to report this behavior.

In Powertools v3 we have dropped support for Pydantic v1 and are only supporting Pydantic v2 which is why we are no longer exporting pydantic types directly and allowing customers to import them directly from Pydantic. First, I must say that I agree with your suggestion that we need to improve our documentation and upgrade guide to make it clear to customers, but I don't think we should revert this change for a few reasons:

1 - Pydantic V2 was a complete refactoring of the Pydantic project and they made several changes including, but not limited, to the way they export types, classes, methods, and others. If we continue to expose them directly from Powertools and some export in Pydantic has changed, our customers may get the impression that there is some bug in Powertools and that is not the experience we want to have for our customers.

2 - The way we were doing this was by exposing everything exposed from pydantic to our customers, but there is a long discussion in the Pydantic repository about how Pydantic v2 is slower than v1 when importing and loading things in this new version. We don't want our customers to inadvertently import everything from Pydantic and this could create some slowdown in their functions.

I will be sending a PR today to update our Upgrade Guide and documentation to clarify this change. I will ping you on this PR to get your feedback - if possible.

Thank you very much for bringing this up, I believe that improving our documentation will prevent other customers from having the same issue.

RyanFrench commented 1 day ago

Thank you, I assumed as much but wasn't sure what the new recommended way was to use other pydantic classes within the parser.