Code

Opened 5 years ago

Closed 5 years ago

#10599 closed (fixed)

URLNode raises "Reverse for 'settings.view_name' ... not found."

Reported by: nishio Owned by: nobody
Component: Template system Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

URLNode raises strange exception as below

Reverse for 'settings.new_game' with arguments '(u'1',)' and keyword arguments '{}' not found.

It is because URLNode try to find "project_name.view_name" even if there is no project name. This error message makes users confused. It should fail fast.

I attached a patch.

Index: django/template/defaulttags.py
===================================================================
--- django/template/defaulttags.py      (revision 10138)
+++ django/template/defaulttags.py      (working copy)
@@ -371,6 +371,7 @@
         try:
             url = reverse(self.view_name, args=args, kwargs=kwargs)
         except NoReverseMatch:
+            if "." not in settings.SETTINGS_MODULE: raise
             project_name = settings.SETTINGS_MODULE.split('.')[0]
             try:
                 url = reverse(project_name + '.' + self.view_name,

Attachments (1)

patch.diff (555 bytes) - added by nishio 5 years ago.
patch

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by nishio

patch

comment:1 Changed 5 years ago by mtredinnick

This is a known problem (I'm be surprised if this wasn't a dupe of some other ticket, but I can't find it at the moment), however the proposed fix isn't correct. The presence or otherwise of a period in the settings module's import path isn't indicative of anything about the project directory. We should basically not report anything from that last block if it raises an exception, since it's really just a safety net for beginners.

We do need a better error reporting there, but this isn't the way to do it.

comment:2 Changed 5 years ago by nishio

I agree that the proposal is not correct solution, but I think it is better than now. The following code is also incorrect. It assumes SETTINGS_MODULE is "project_name.settings" style. That's why the error message strange.

project_name = settings.SETTINGS_MODULE.split('.')[0]

This fix is not the better error reporting but a better one.

comment:3 Changed 5 years ago by nishio

Sorry, I made 2 mistake in above comment.

I agree that the proposal is not perfect solution, but I think it is better than now. The following code is also incorrect. It assumes SETTINGS_MODULE is "project_name.settings" style. That's why the error message strange.

project_name = settings.SETTINGS_MODULE.split('.')[0]

This fix is not the best error reporting but a better one.

comment:4 Changed 5 years ago by jacob

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

(In [10351]) [1.0.X] Fixed #9005: don't wig out when reversing a URL if SETTINGS_MODULE isn't set. While I was there, I fixed #10599 by re-raising the original error message, which is almost always a better idea. Thanks, Eric. Backport of r10350 from trunk.

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.