Skip to content

Bug: aws_lambda_powertools.utilities.parser.pydantic does not exist anymore while mentioned in the documentation #5390

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
VladimirSvoboda opened this issue Oct 15, 2024 · 6 comments

Comments

@VladimirSvoboda
Copy link

Expected Behaviour

Contrarily to what is stated in the documentation, since the version 3 (and more precisely the pull request #4502) , it is not possible anymore to import any Pydantic module/function through aws_lambda_powertools.utilities.parser.pydantic.

In my case, I would like to be able to import the decorator @field_serializer

Current Behaviour

python -c "from aws_lambda_powertools.utilities.parser.pydantic import field_serializer"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'aws_lambda_powertools.utilities.parser.pydantic'

Code snippet

python3 -m venv venv
source venv/bin/activate
pip install aws-lambda-powertools[all]==3.1.0
python -c "from aws_lambda_powertools.utilities.parser.pydantic import field_serializer"

Possible Solution

  1. Restore the file aws_lambda_powertools/utilities/parser/pydantic.py removed in feat(parser): Allow primitive data types to be parsed using TypeAdapter #4502
  2. Correct the documentation

Steps to Reproduce

Execute the following code snippet

python3 -m venv venv
source venv/bin/activate
pip install aws-lambda-powertools[all]==3.1.0
python -c "from aws_lambda_powertools.utilities.parser.pydantic import field_serializer"

Powertools for AWS Lambda (Python) version

3.1.0

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

@VladimirSvoboda VladimirSvoboda added bug Something isn't working triage Pending triage from maintainers labels Oct 15, 2024
Copy link

boring-cyborg bot commented Oct 15, 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

Hey @VladimirSvoboda! thanks a lot for opening this issue! In fact we are not exporting Pydantic objects from parser and we explain that in our upgrade guide to v3.

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 that we need to update our documentation and we are #5262. I'll try to merge this PR as soon as possible to prevent this type of error.

Let me explain some reasons why we removed this export:

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/pydantic#6748 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.

We are working to improve this documentation in this PR - #5262

Can you please try importing them directly from Pydantic?

Thanks

@leandrodamascena leandrodamascena added not-a-bug and removed triage Pending triage from maintainers bug Something isn't working labels Oct 17, 2024
@leandrodamascena leandrodamascena moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Oct 17, 2024
@VladimirSvoboda
Copy link
Author

Thanks for your answer. I now import directly from pydantic to fix the issue.
Please note that the error regarding these imports in the documentation is currently not fixed by #5262

@anafalcao
Copy link
Contributor

Hi @VladimirSvoboda ! Thank you for your follow-up and for bringing this to our attention. You're absolutely right that the documentation issue hasn't been fully addressed by #526 yet. We appreciate your patience and the workaround you've implemented using direct imports from pydantic.

We're actively working on a comprehensive update to the Parser documentation, which will include fixing the import errors you've mentioned. We expect to release these changes within the next few weeks. In the meantime, if you encounter any other issues, please don't hesitate to let us know.
Thanks!

@leandrodamascena
Copy link
Contributor

Hey @VladimirSvoboda! We are closing this issue because we merged the PR! We are releasing next week with this fix.

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

github-actions bot commented Nov 7, 2024

⚠️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
Projects
Development

No branches or pull requests

3 participants