﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7524	Not concrete exception when urls module imports invalid modules.	Petr Marhoun <petr.marhoun@…>	nobody	"This code is in django.core.urlresolvers:

{{{
#!python

    def _get_urlconf_module(self):
        try:
            return self._urlconf_module
        except AttributeError:
            try:
                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
            except Exception, e:
                # Either an invalid urlconf_name, such as ""foo.bar."", or some
                # kind of problem during the actual import.
                raise ImproperlyConfigured, ""Error while importing URLconf %r: %s"" % (self.urlconf_name, e)
            return self._urlconf_module
    urlconf_module = property(_get_urlconf_module)

}}}

It was sufficient for configuration files (almost) without imports:

{{{
#!python

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^articles/2003/$', 'news.views.special_case_2003'),
    (r'^articles/(\d{4})/$', 'news.views.year_archive'),
    (r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
    (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)

}}}

But now it is possible to use this file:

{{{
#!python

from django.conf.urls.defaults import *
from news import views

urlpatterns = patterns('',
    (r'^articles/2003/$', views.special_case_2003),
    (r'^articles/(\d{4})/$', views.year_archive),
    (r'^articles/(\d{4})/(\d{2})/$', views.month_archive),
    (r'^articles/(\d{4})/(\d{2})/(\d+)/$', views.article_detail),
)

}}}

This file imports views, views probably import models and there are many possibilities for syntax errors. It is very difficult to tell where the error is.

So I would like to propose to show original exception in the debug mode:

{{{
#!python

    def _get_urlconf_module(self):
        try:
            return self._urlconf_module
        except AttributeError:
            try:
                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
            except Exception, e:
                # Either an invalid urlconf_name, such as ""foo.bar."", or some
                # kind of problem during the actual import.
                from django.conf import settings
                if settings.DEBUG:
                    raise
                else:
                    raise ImproperlyConfigured, ""Error while importing URLconf %r: %s"" % (self.urlconf_name, e)
            return self._urlconf_module
    urlconf_module = property(_get_urlconf_module)
}}}"		closed	Core (Other)	dev		fixed		rokclimb15@…	Accepted	1	0	0	0	0	0
