Opened 8 years ago

Closed 8 years ago

#16229 closed Cleanup/optimization (invalid)

django.core.validators not usable without a DJANGO_SETTINGS_MODULE

Reported by: Jonas H. Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description reads (after catching a Django settings ImportError):

It's OK if Django settings aren't configured.

However, using the validate_email validator crashes without a DJANGO_SETTINGS_MODULE:

>>> from django.core.validators import validate_email
>>> validate_email('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "django/core/", line 120, in __call__
    super(EmailValidator, self).__call__(value)
  File "django/core/", line 40, in __call__
    raise ValidationError(self.message, code=self.code)
  File "django/core/", line 60, in __init__
    message = force_unicode(message)
  File "django/utils/", line 71, in force_unicode
    s = unicode(s)
  File "django/utils/", line 108, in __unicode_cast
    return self.__func(*self.__args, **self.__kw)
  File "django/utils/translation/", line 87, in ugettext
    return _trans.ugettext(message)
  File "django/utils/translation/", line 49, in __getattr__
    if settings.USE_I18N:
  File "django/utils/", line 180, in __getattr__
  File "django/conf/", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Change History (3)

comment:1 Changed 8 years ago by Stephen Burrows

Resolution: invalid
Status: newclosed
Type: BugCleanup/optimization
Version: 1.3SVN

This is not a bug. It's not even a documentation error. Looking at the code, the comment only refers to the setting of URL_VALIDATOR_USER_AGENT and makes no claims about the running of the EmailValidator. I suppose the comment could be clarified. However, it doesn't really seem necessary.

comment:2 Changed 8 years ago by Jonas H.

Resolution: invalid
Status: closedreopened

Reopening as this comment should be fixed.

comment:3 Changed 8 years ago by Luke Plant

Resolution: invalid
Status: reopenedclosed

I agree with melinath that fixing the comment is unnecessary - it is clear enough that it refers to settings being optional for the purpose of setting URL_VALIDATOR_USER_AGENT.

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