Opened 10 years ago

Closed 10 years ago

#23412 closed Bug (invalid)

Unable to import django.forms.util.ValidationError

Reported by: Nathan Osman Owned by: nobody
Component: Forms Version: 1.7
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

I ran the following commands on a completely clean installation of Ubuntu Server 14.04.1:

apt-get install python-pip
pip install Django

I then opened the Python interpreter and ran the following commands:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import forms
>>> forms.util.ValidationError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'util'

It would appear that django.forms.util is missing. This is very odd since I can confirm that the relevant file does indeed exist:

# cd /usr/local/lib/python2.7/dist-packages/django/forms
# ls
extras      formsets.py   forms.pyc     models.py   util.pyc   widgets.py
fields.py   formsets.pyc  __init__.py   models.pyc  utils.py   widgets.pyc
fields.pyc  forms.py      __init__.pyc  util.py     utils.pyc

I have confirmed this error on two other machines running Ubuntu 14.04. According to the contents of the file, the module is set to be removed in Django 1.9, so it should still work in Django 1.7.

Change History (2)

comment:1 by Simon Charette, 10 years ago

django.form.util used to be defined as a side effect of all the imports in django/forms/__init__.py.

Since we don't import this module anymore, to prevent firing DeprecatingWarnings, it's never assigned as a property to the django.forms module. You can validate this is the case by trying to access forms.util once you explicitly imported django.forms.util.

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import forms
>>> forms.util
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'util'
>>> from django.forms import util
>>> forms.util
<module 'django.forms.util' from '/home/simon/.virtualenvs/c9a1b5f64fd59792/local/lib/python2.7/site-packages/django/forms/util.pyc'>

Since accessing django.forms.util without explicitly importing the util module used to works only because of import side effects I'm tempted to mark this ticket as won't fix. I'm not even sure there's a way to lazily expose the util module to support your case without triggering the deprecating warnings.

comment:2 by Claude Paroz, 10 years ago

Resolution: invalid
Status: newclosed

ValidationError has to be imoprted from django.core.exceptions, and it is documented so for some time I think. Of course, you can theoratically import various names from each file where it is imported also, but we cannot guarantee that the imports will work over time. If the old import location were to be documented in a recent documentation version, that would be another story.

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