[Django] #36809: Allow EmailValidator to return 'domain_part' in ValidationError params

6 views
Skip to first unread message

Django

unread,
Dec 18, 2025, 1:13:17 PM12/18/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
---------------------------------+-----------------------------------------
Reporter: Daniel E Onetti | Type: Uncategorized
Status: new | Component: Core (Other)
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Currently, the EmailValidator only provides the full 'value' in the params
dictionary when a ValidationError is raised. However, in many use cases,
developers need to customize error messages based specifically on the
domain part of the email (e.g., "The domain %(domain_part)s is not
allowed").

This change adds 'domain_part' to the params dictionary in
EmailValidator.__call__, bringing it in line with how other validators
provide decomposed parts of the validated value. This allows for more
granular and helpful error messages for end users.

I have already prepared a patch with tests and verified that it passes all
style (flake8) and functional checks.
--
Ticket URL: <https://code.djangoproject.com/ticket/36809>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 19, 2025, 6:20:10 AM12/19/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
---------------------------------+----------------------------------------
Reporter: Daniel E Onetti | Owner: Kundan Yadav
Type: Uncategorized | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Kundan Yadav):

* owner: (none) => Kundan Yadav
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36809#comment:1>

Django

unread,
Dec 19, 2025, 8:20:22 AM12/19/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
---------------------------------+----------------------------------------
Reporter: Daniel E Onetti | Owner: Kundan Yadav
Type: Uncategorized | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Comment (by Kundan Yadav):

hey can i work on it or is it already being worked on by you
--
Ticket URL: <https://code.djangoproject.com/ticket/36809#comment:2>

Django

unread,
Dec 19, 2025, 8:22:34 AM12/19/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
-------------------------------------+-------------------------------------
Reporter: Daniel E Onetti | Owner: Daniel E
Type: | Onetti
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: EmailValidator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* has_patch: 0 => 1
* keywords: => EmailValidator
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1
* needs_tests: 0 => 1
* owner: Kundan Yadav => Daniel E Onetti
* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization

Comment:

Hello Daniel! Thanks for the report, for taking the time to prepare a
patch, and for following the contributing guide. I appreciate that.

I agree that the use case is valid and that being able to reference the
domain in error messages can be genuinely useful. That said, I am not
convinced that simply adding `domain_part` to `ValidationError.params` is
the best fit for Django core. It solves the immediate problem, but does so
in a way that feels quite specific rather than structural. It also risks
committing to an API that only partially reflects how `EmailValidator`
actually works.

Looking at the other validators in this module, there is a clear pattern
of separating parsing, normalization, and validation into distinct steps
or methods, even when the final error surface remains simple.
`EmailValidator` is somewhat inconsistent here: it already decomposes the
value into user and domain components, but does so inline inside
`__call__`, with no clear extension points. Adding a single extra param
addresses the symptom rather than the structure.

I think a more Django aligned approach would be to re-evaluate
`EmailValidator` as a whole and give it clearer, overridable validation
hooks, while keeping full backward compatibility. For example, introducing
explicit methods like `validate_recipient()` and `validate_domain()`,
called from `__call__`, would allow customization via subclassing without
re-parsing the email or wrapping errors. The existing
`validate_domain_part()` could be kept for compatibility and potentially
deprecated later, since it currently returns a boolean.

So in short, I agree with the motivation, but I think the solution needs
to be broader and more structural than the current proposal in order to
align better with Django's existing validator patterns.
--
Ticket URL: <https://code.djangoproject.com/ticket/36809#comment:3>

Django

unread,
Dec 19, 2025, 8:23:13 AM12/19/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
-------------------------------------+-------------------------------------
Reporter: Daniel E Onetti | Owner: Daniel E
Type: | Onetti
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: EmailValidator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

Replying to [comment:2 Kundan Yadav]:
> hey can i work on it or is it already being worked on by you

Hello Kundan, there is an initial PR already for this issue by Daniel, so
I have re-assigned this to them,
--
Ticket URL: <https://code.djangoproject.com/ticket/36809#comment:4>

Django

unread,
Dec 19, 2025, 4:07:42 PM12/19/25
to django-...@googlegroups.com
#36809: Allow EmailValidator to return 'domain_part' in ValidationError params
---------------------------------+--------------------------------------
Reporter: Daniel E Onetti | Owner: (none)
Type: Uncategorized | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Jacob Walls):

Hey Kundan, did you have this form open in your browser and resave it?
Notice you overwrote all of the previous triage. Could you set it back,
please?
--
Ticket URL: <https://code.djangoproject.com/ticket/36809#comment:7>
Reply all
Reply to author
Forward
0 new messages