JoshData / python-email-validator

A robust email syntax and deliverability validation library for Python.
The Unlicense
1.14k stars 112 forks source link

Validation fails witn OpenAPI openapi-spec-validator #129

Closed verhovensky closed 7 months ago

verhovensky commented 8 months ago

Env: Python 3.12

Dependencies:

python = "^3.12"
fastapi = "^0.109.0"
pydantic = {extras = ["email"], version = "^2.6.1"}
dependency-injector-fork = "^4.42.1"
pyyaml = "^6.0"
starlette-exporter = "^0.21.0"
brotli-asgi = "^1.4.0"
uvicorn = {extras = ["standard"], version = "^0.27.1"}
typer = "^0.9.0"
httpx = "^0.26.0"
pydantic-settings = "^2.1.0"
elastic-apm = "^6.20.0"
sqlalchemy = "^2.0.27"
phonenumbers = "^8.13.30"
alembic = "^1.13.1"
asyncpg = "^0.29.0"
fastapi-filter = "^1.1.0"
pytz = "^2024.1"
aiobotocore = "^2.11.1"
xlsxwriter = "^3.1.9"
python-multipart = "^0.0.9"
redis = "^5.0.1"
openapi-spec-validator = "^0.7.1"

Steps to reproduce: Install email-validator package and try running validation on Open Api schemas

tests-1     | E   TypeError: compile() arg 1 must be a string, bytes or AST object
tests-1     | _____________ test_when_spec_is_called_then_spec_is_returned[json] _____________
tests-1     | tests/test_cli/test_api.py:17: in test_when_spec_is_called_then_spec_is_returned
tests-1     |     spec(encoder=encoder)
tests-1     | app/cli/api.py:34: in spec
tests-1     |     openapi_json = web_app.openapi()
tests-1     | /env/lib/python3.12/site-packages/fastapi/applications.py:981: in openapi
tests-1     |     self.openapi_schema = get_openapi(
tests-1     | /env/lib/python3.12/site-packages/fastapi/openapi/utils.py:530: in get_openapi
tests-1     |     return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True)  # type: ignore
tests-1     | /env/lib/python3.12/site-packages/pydantic/networks.py:417: in _validate
tests-1     |     return validate_email(__input_value)[1]
tests-1     | /env/lib/python3.12/site-packages/pydantic/networks.py:696: in validate_email
tests-1     |     parts = email_validator.validate_email(email, check_deliverability=False)
tests-1     | /env/lib/python3.12/site-packages/email_validator/validate_email.py:112: in validate_email
tests-1     |     domain_part_info = validate_email_domain_name(domain_part, test_environment=test_environment, globally_deliverable=globally_deliverable)
tests-1     | /env/lib/python3.12/site-packages/email_validator/syntax.py:329: in validate_email_domain_name
tests-1     |     domain = idna.uts46_remap(domain, std3_rules=False, transitional=False)
tests-1     | /env/lib/python3.12/site-packages/idna/core.py:310: in uts46_remap
tests-1     |     from .uts46data import uts46data
tests-1     | <frozen importlib._bootstrap>:1360: in _find_and_load
tests-1     |     ???
tests-1     | <frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
tests-1     |     ???
tests-1     | <frozen importlib._bootstrap>:935: in _load_unlocked
tests-1     |     ???
tests-1     | /env/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:177: in exec_module
tests-1     |     source_stat, co = _rewrite_test(fn, self.config)
tests-1     | /env/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:359: in _rewrite_test
tests-1     |     tree = ast.parse(source, filename=strfn)
tests-1     | /usr/local/lib/python3.12/ast.py:52: in parse
tests-1     |     return compile(source, filename, mode, flags,
tests-1     | E   TypeError: compile() arg 1 must be a string, bytes or AST object
JoshData commented 8 months ago

The exception shows a problem (which I don't understand) that appears to be related to pytest and possibly the idna package that this library uses, so I don't think the problem is in this library.

verhovensky commented 8 months ago

But I had idna & pytest in my dependencies earlier and nothing happened. Just after installing email-validator I face the error. Nevertheless It's up to you to close the issue, thanks for the feedback!

JoshData commented 8 months ago

Maybe your version of idna changed?

JoshData commented 7 months ago

I'm going to close the issue because I don't understand what pytest is doing so I don't have any hope of figuring it out (in a reasonable amount of time). Feel free to re-open or comment if there's anything specific I can do.