Opened 8 years ago

Closed 8 years ago

#13371 closed (duplicate)

reverse() causes unnecessary infinite recursion when used in urlconf

Reported by: nh2 Owned by: nobody
Component: Uncategorized Version: 1.2-beta
Severity: Keywords:
Cc: nh2@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



(r'^$', views.main, {}, 'main'),
(r'^login/$', django.contrib.auth.views.login, {...[parameters]... , 'next': reverse('main')}, 'login'),

in urlconf.
The idea is easy: After a successful login, redirect to the main view, whatever its URL is (were DRY and don't want to hardcode the URL more than once, right?).

However, we get

ImproperlyConfigured at /
The included urlconf [myproject].urls doesn't have any patterns in it

whenever we call reverse([whatever string]) as Django tries to evaluate reverse('main') although it is specified as value for 'next' and therefore cannot be the answer to our url lookup query. As reverse('main') matches reverse([whatever string]), we get an infinite recursion which seems to be catched by an ImproperlyConfigured raise in some way.

Do you agree?

Change History (3)

comment:1 Changed 8 years ago by nh2

Cc: nh2@… added

comment:2 Changed 8 years ago by nh2


I just noticed 'next' is not a parameter for django.contrib.auth.views.login, but reverse() should nevertheless not fail being used in urlconfs at positions which cannot evaluate to the URL we are looking for.

comment:3 Changed 8 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

Duplicate of #11712. The issue here is that reverse() isn't lazy, so if you use it in your URLconf definition, it tries to resolve before the URLconf has been fully defined.

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