-
Notifications
You must be signed in to change notification settings - Fork 429
Cannot import batch with pydantic already imported, without email-validator #998
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
Comments
How critical is this for you? Can we finish other papercuts to make our upcoming release then work on this right after? Because we assume customers will install our "pydantic" extra package which includes email-validator, we didn't foresee the latter lib impact since Pydantic is a big outlier already. @ran-isenberg Question: How critical is it to have email-validator vs EmailStr given it's a SES event? I'd strive for option 2 tho I can't recall if this can be a non-breaking change. If it is a breaking change, then we could As always, thank you for helping us improve @huonw !! |
I think it's great to have the email validation but it's not a must. I mean, if you are using a parser, these are the areas it excels. Another option is to check if emailstr can be imported, and if not define it as str maybe? |
Not critical: totally happy for you to prioritise as you see fit. As you say, this is "only" 2MB on top of the large pydantic package (and we happen to use a bunch of other large ones too). |
@huonw we're prepping for V2 this week and removed email-validator dependency, as part of other package size optimizations we've made -- For PyPi, we're now down to ~200K, and for Layers with all dependencies + compiled Pydantic down to ~2M. Thank you for the prolonged patience here! |
Closing as we're wrap to launch V2. |
|
What were you trying to accomplish?
We're trying to use the batch utility to process SQS records. We're using Pydantic for various things, including the messages pushed into SQS. If we've imported pydantic before importing
aws_lambda_powertools.utilities.batch
we hit an exception due toemail-validator
not being installed.We're not using pydantic's
EmailStr
, and so haven't installedemail-validator
and would prefer not to if possible. (NB. email-validator itself is small (< 100K), but it seems to requirednspython
which is almost 2MB.)Expected Behavior
Using batch classes shouldn't require
email-validator
to be installed, even if Pydantic has already been imported.Current Behavior
Possible Solution
email_validator
too, although this worsens the user/typing experience for those who are using pydantic without email validationbatch
could importDynamoDBStreamRecordModel
(etc) in a way that doesn't trigger also importenvelopes
, orenvelopes/apigw.py
could importAPIGatewayProxyEventModel
in a way that doesn't importses
ses
(etc):email-validator
: if email-validator doesn't exist, then the models don't function, in some way that has a useful error messagestr
instead ofEmailStr
, if email-validator isn't installed(Either of the last two would potentially also resolve the related issue that it is impossible to use
aws_lambda_powertools.utilities.parser
without email-validator, even if avoiding the SES models. Seepython -c 'import aws_lambda_powertools.utilities.parser'
.)Steps to Reproduce (for bugs)
pip install aws-lambda-powertools==1.24.2 aws-xray-sdk==2.9.0 boto3==1.20.48 botocore==1.23.48 fastjsonschema==2.15.3 future==0.18.2 jmespath==0.10.0 pydantic==1.9.0 python-dateutil==2.8.2 s3transfer==0.5.1 six==1.16.0 typing_extensions==4.0.1 urllib3==1.26.8 wrapt==1.13.3 python -c 'import pydantic; from aws_lambda_powertools.utilities import batch'
Note: removing the
import pydantic;
works fine, since the check is just based on whether pydantic has been imported, not whether it is importable.https://github.com/awslabs/aws-lambda-powertools-python/blob/168ec482502fb4a1a22038e3a2041459926e6591/aws_lambda_powertools/utilities/batch/base.py#L31
Environment
pip
command above)The text was updated successfully, but these errors were encountered: