#23224 closed Bug (fixed)

Document EmailValidator domain whitelist parameter

Reported by: egberts Owned by: nobody
Component: Documentation Version: 1.7-alpha-2
Severity: Normal Keywords: SMTP email syntax
Cc: areski@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am unable to validate "webmaster@lab" email address using EmailField() validator.

Examination of Test framework (TEST_DATA in tests.py) shows that it won't take the "abc@bar" email format.

TEST_DATA =
...
 (validate_email, 'abc@bar', ValidationError)
...

Did I miss something new amongst the vast IETF specifications regarding this new restrictive email syntax? Or must we expand our 20yo Lab domain name to something like 'lab.test'?

Tarball File Used: django-django-1.7a3-1364-gedcc75e.zip

Change History (6)

comment:1 Changed 12 months ago by CollinAnderson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

as a data point: yes, django 1.6 gives the same error message

>>> from django import forms
>>> forms.EmailField().clean('webmaster@lab')
ValidationError: [u'Enter a valid email address.']

comment:2 Changed 12 months ago by areski

  • Cc areski@… added

FYI this is where django implement the email validation: https://github.com/django/django/blob/master/django/core/validators.py#L119
documentation on validators: https://docs.djangoproject.com/en/dev/ref/forms/validation/#using-validation-in-practice

From this, you will notice that there is an easy way to validate abc@bar:

from django.forms import EmailField
from django.core.validators import EmailValidator

class MyEmailField(EmailField):
    default_validators = [EmailValidator(whitelist=['bar'])]

MyEmailField().clean('abc@bar')

comment:3 Changed 12 months ago by timgraham

  • Component changed from Testing framework to Documentation
  • Summary changed from Unable to validate "webmaster@lab" via EmailField() validation to Document EmailValidator domain whitelist parameter
  • Triage Stage changed from Unreviewed to Accepted

We should document the solution described by areski.

comment:4 Changed 12 months ago by areski

Here a PR for to document the solution https://github.com/django/django/pull/3056

Last edited 12 months ago by areski (previous) (diff)

comment:5 Changed 12 months ago by timgraham

  • Has patch set

comment:6 Changed 12 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 2a4492aecb50122f7cc2c643f7ea5b086f301165:

Fixed #23224 - Documented EmailValidator.

Note: See TracTickets for help on using tickets.
Back to Top