Code

Opened 3 years ago

Closed 3 years ago

#16229 closed Cleanup/optimization (invalid)

django.core.validators not usable without a DJANGO_SETTINGS_MODULE

Reported by: jonash 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

https://code.djangoproject.com/browser/django/trunk/django/core/validators.py#L16 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/validators.py", line 120, in __call__
    super(EmailValidator, self).__call__(value)
  File "django/core/validators.py", line 40, in __call__
    raise ValidationError(self.message, code=self.code)
  File "django/core/exceptions.py", line 60, in __init__
    message = force_unicode(message)
  File "django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "django/utils/functional.py", line 108, in __unicode_cast
    return self.__func(*self.__args, **self.__kw)
  File "django/utils/translation/__init__.py", line 87, in ugettext
    return _trans.ugettext(message)
  File "django/utils/translation/__init__.py", line 49, in __getattr__
    if settings.USE_I18N:
  File "django/utils/functional.py", line 180, in __getattr__
    self._setup()
  File "django/conf/__init__.py", 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.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by melinath

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed
  • Type changed from Bug to Cleanup/optimization
  • Version changed from 1.3 to SVN

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 3 years ago by jonash

  • Resolution invalid deleted
  • Status changed from closed to reopened

Reopening as this comment should be fixed.

comment:3 Changed 3 years ago by lukeplant

  • Resolution set to invalid
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.