Opened 9 years ago

Closed 6 years ago

#3221 closed enhancement (fixed)

[patch] unhelpful error message when include() set incorrectly

Reported by: imbaczek@… Owned by: oggie_rob
Component: Core (Other) Version:
Severity: minor Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

instead of 'module' has no attribute 'urlpatterns', a more useful error message would be nice to have, as I just wasted 30 mins of time just to notice I forgot to append .urls in an include() in urlconf.

I've patched my django.core.urlresolvers with this:

Index: urlresolvers.py
===================================================================
--- urlresolvers.py     (wersja 4270)
+++ urlresolvers.py     (kopia robocza)
@@ -157,6 +157,8 @@
         match = self.regex.search(path)
         if match:
             new_path = path[match.end():]
+            if not hasattr(self.urlconf_module, 'urlpatterns'):
+                raise AttributeError('urlpatterns in module %s not found, is the parent urlconf correct?'%self.urlconf_module.__name__)
             for pattern in self.urlconf_module.urlpatterns:
                 try:
                     sub_match = pattern.resolve(new_path)

Attachments (1)

3221_import_error.diff (725 bytes) - added by oggie_rob 8 years ago.
Catch ImpotError & raise ValidationError to clarify location/problem with import

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by Simon G. <dev@…>

  • Has patch set
  • Summary changed from unhelpful error message when include() set incorrectly to [patch] unhelpful error message when include() set incorrectly
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 8 years ago by oggie_rob

  • Owner changed from nobody to oggie_rob

Changed 8 years ago by oggie_rob

Catch ImpotError & raise ValidationError to clarify location/problem with import

comment:3 Changed 8 years ago by oggie_rob

Fixed by re-throwing error with more explicit message.

comment:4 Changed 6 years ago by seveas

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

A slightly different more useful error message has found its way into the trunk already.

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