Skip to content

Bug: Pydantic "escape hatch" no longer available #5352

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
areifert opened this issue Oct 8, 2024 · 6 comments
Closed

Bug: Pydantic "escape hatch" no longer available #5352

areifert opened this issue Oct 8, 2024 · 6 comments
Assignees

Comments

@areifert
Copy link

areifert commented Oct 8, 2024

Expected Behaviour

The Parser documentation FAQ states that an "escape hatch" mechanism can be used to access imports from the base pydantic library that are not otherwise available as imports from aws_lambda_powertools.utilities.parser: https://docs.powertools.aws.dev/lambda/python/latest/utilities/parser/#faq.

Current Behaviour

aws_lambda_powertools.utilities.parser.pydantic is not a valid import path. (This may have been an older feature that has since been removed.)

Code snippet

from aws_lambda_powertools.utilities.parser.pydantic import <what you'd like to import'>

Possible Solution

If all pydantic imports can be made available at aws_lambda_powertools.utilities.parser.pydantic (likely by modifying aws_lambda_powertools/utilities/parser/__init__.py), that would be ideal. Otherwise, the documentation should be updated to remove this feature.

Steps to Reproduce

Attempting to import anything from aws_lambda_powertools.utilities.parser.pydantic will result in an import error.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

Lambda Layers

Debugging logs

No response

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

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

@areifert
Copy link
Author

areifert commented Oct 8, 2024

For reference, I was trying to import computed_field, but

from aws_lambda_powertools.utilities.parser import computed_field

is not a valid import.

@leandrodamascena
Copy link
Contributor

Hey @areifert 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 already doing this. 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.

Can you please try importing them directly from Pydantic?

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

areifert commented Oct 9, 2024

@leandrodamascena: this is perfect, thanks for the detailed response. I was able to import computed_field directly from Pydantic.

It looks like some Pydantic exports are still available from aws_lambda_powertools.utilities.parser (e.g., BaseModel); going forward, is it recommended that all of these be imported directly from Pydantic instead?

(P.S.: I've been using Powertools for only a month or two and am really enjoying it, thanks for all you do!)

@leandrodamascena
Copy link
Contributor

It looks like some Pydantic exports are still available from aws_lambda_powertools.utilities.parser (e.g., BaseModel); going forward, is it recommended that all of these be imported directly from Pydantic instead?

This is expected because now we just export BaseModel, Field, ValidationError, field_validator, and model_validator, the functions/classes that we must use in our utilities, including parser. The old way we were exporting * from pydantic and errors.

(P.S.: I've been using Powertools for only a month or two and am really enjoying it, thanks for all you do!)

Hey, that's awesome to hear! We're here to support you in any way you need. Feel free to open an issue or talk to us on our Discord server https://discord.gg/B8zZKbbyET

Closing this issue.

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

github-actions bot commented Oct 9, 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

2 participants