Skip to content

Return None for MX when deliverability is unknown - #191

Open
ainuo-AI wants to merge 1 commit into
JoshData:mainfrom
ainuo-AI:fix/mx-on-unknown-deliverability
Open

ainuo-AI wants to merge 1 commit into
JoshData:mainfrom
ainuo-AI:fix/mx-on-unknown-deliverability

Conversation

@ainuo-AI

Copy link
Copy Markdown

Fixes #190.

When a DNS deliverability check times out or has no usable nameserver, validate_email() returns an accepted address without an mx attribute. A caller following the documented ValidatedEmail.mx API then gets AttributeError instead of None, making it harder to distinguish a temporary lookup problem from a successful check.

Assign mx from the lookup result unconditionally, matching both the README and the existing handling of mx_fallback_type. Make the annotation optional and retain the existing equality behavior with optional MX results. Regression tests exercise the public validator for timeout and no-nameserver outcomes, including as_dict().

The existing report provides a constructed timeout reproduction. I also verified the public API with an ordinary dns.resolver.Resolver pointing only at a bound, nonresponding loopback UDP socket: reading .mx fails before this fix and returns None afterward. This is controlled test data, not a production DNS trace.

Validation:

  • Both new regression cases fail before the fix.
  • Python 3.14.10, pinned project dependencies: 342 tests pass; the one Internet-dependent test is deselected, as in the project's offline CI test target.
  • Official mypy and flake8 checks pass.
  • Python 3.12.10: 341 pass and one unrelated IPv4-mapped IPv6 display assertion fails. That same assertion also fails with the original validator implementation; the baseline output is retained locally. This PR leaves that behavior unchanged.

Disclosure: OpenAI Codex assisted with investigation, implementation, tests, and this PR description. No human review or upstream acceptance is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValidatedEmail.mx is missing, not None, when the deliverability check times out

1 participant