Closed
Description
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
- Restore the file
aws_lambda_powertools/utilities/parser/pydantic.py
removed in feat(parser): Allow primitive data types to be parsed using TypeAdapter #4502 - 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
Metadata
Metadata
Assignees
Type
Projects
Status
Closed
Milestone
Relationships
Development
No branches or pull requests
Activity
boring-cyborg commentedon 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 commentedon Oct 17, 2024
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
VladimirSvoboda commentedon Oct 18, 2024
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 commentedon Oct 21, 2024
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 commentedon Nov 7, 2024
Hey @VladimirSvoboda! We are closing this issue because we merged the PR! We are releasing next week with this fix.
3 remaining items