Random NoReverseMatch

57 views
Skip to first unread message

Alberto Piai

unread,
Aug 15, 2008, 12:03:16 PM8/15/08
to django...@googlegroups.com
Hi all,

First of all thanks for all the effort you've put into django, it's a
great framework.

I'm having a lot of problems with the reverse url matching: everything
works fine for a while (some minutes), then all of a sudden some page
triggers a NoReverseMatch exception. The problem is that it happens
randomly, on different pages, sometimes immediately after starting the
server and sometimes after some requests. Since it seems to be random,
I have no idea where to start debugging this. I'm using reverse() and
the url tag all over the place (with named url patterns), so I really
rely on it. I'm on a VPS with lighttpd and fastcgi, and each time that
a user triggers the exception the whole server just stops working and
every request gets a NoReverseMatch (possibly from other views and
other urls).

This is getting really frustrating... is anyone experiencing similar
problems? Do you have any idea where to start debugging this? What
info should I provide to help you understand the problem? I've
double-checked every place where i use the url tag or reverse(), and
all the named patterns.

Thanks a lot,


Alberto

Alberto Piai

unread,
Aug 15, 2008, 4:20:19 PM8/15/08
to django...@googlegroups.com
On Fri, Aug 15, 2008 at 6:03 PM, Alberto Piai <albert...@gmail.com> wrote:
[snip]

> This is getting really frustrating... is anyone experiencing similar
> problems? Do you have any idea where to start debugging this? What
> info should I provide to help you understand the problem? I've
> double-checked every place where i use the url tag or reverse(), and
> all the named patterns.

Forgot to add that apache+mod_python has the same problem, while
everything works fine if i run django's dev server. Also, from the
shell all the reverse calls work fine.

Alberto

Julien Phalip

unread,
Aug 15, 2008, 6:01:49 PM8/15/08
to Django users
Hi,

It's likely that there is a typo somewhere in your templates, either
you didn't write the view name properly, or you didn't provide the
right parameters.
In the error message, there should be the name of the view. Look up
every occurrence et double check that you haven't made any typo. If
you still can't find the cause, please give us some more details, like
the full traceback for example.

Cheers,

Julien

Alberto Piai

unread,
Aug 16, 2008, 2:16:10 PM8/16/08
to Django users

On Aug 16, 12:01 am, Julien Phalip <jpha...@gmail.com> wrote:
> Hi,
>
> It's likely that there is a typo somewhere in your templates, either
> you didn't write the view name properly, or you didn't provide the
> right parameters.
> In the error message, there should be the name of the view. Look up
> every occurrence et double check that you haven't made any typo.

I'm checking everything again. But actually I don't think the
problem's there, as everything works fine when run from django's dev
server, and now it's been working fine for some hours even on lighttpd
+fcgi. When the problem appears again I'll send the traceback.

Thanks for you help,

Alberto

Robin

unread,
Aug 25, 2008, 10:13:21 AM8/25/08
to Django users
Hello,

i have the same exception and exactly as Julien explained in the dev
server works fine ... and also works fine with fast_cgi, but I am
using apache + mod_wsgi and it didn't work with the same problem:
NoReverseMatch

Has any of you any clue to this error ?

thanks in advance,
r

koenb

unread,
Aug 25, 2008, 3:40:35 PM8/25/08
to Django users
I guess you are seeing the bug reported in #6379. You probably have an
import error somewhere, but it is being hidden by the NoReverseMatch
exception that is raised for anything that goes wrong.

Koen

tonemcd

unread,
Aug 28, 2008, 1:20:43 PM8/28/08
to Django users
Well, this bit me a while back when I svn-up'ed from trunk and I got
fed up of changing my django.pth to point to trunk_r7971, so I was
determined to get it sorted out.

The first thing is that the NoReverseMatch error seems to be a catch-
all for a variety of exceptions, so if you can, check out your imports
as Koen outlines below.

However, I think that in this case it is far more likely that you have
some data that is triggering the NoReverseMatch exception, as you say
it happens randomly, and I think what is happening is your arguments
to {% url ... %} are not compatible with what your named url is
expecting to see.

This is what happened to me; my urls are of the form;

today/<group>/agenda

where <group> is letters (upper and lowercase), numbers and '-', so
these are valid stgp01, st2gp2-18 etc.

I used this match to begin with;
url(r'^today/(?P<group>[\w,-]+)/agenda$

from http://python.about.com/od/regularexpressions/a/regexprimer.htm
you can see that \w handles alphanumerics and _.

This is what killed it;

/today/st4gp8&9/agenda

With r7971 this would not have been a problem (well actually it would
have been a problem because the URL wouldn't work), but at least it
wouldn't give you an error. Now it does (it was changed in r8211, see
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges for
more details).

The solution for me was to include & and friends into the regex, so I
added \W as well (the above URL has details).

My final URL pattern is url(r'^today/(?P<group>[\w,\W-]+)/agenda$ and
this works just fine.

I don't know what you're matching, but I'd hazard a guess that what
you're pumping out is not compatible with what your URL regex is
expecting to see.

This seems like a prime example of something that needs a slightly
more descriptive error message, but whether that's possible or not, I
don't know (I did dig around in urlresolvers.py, but it went rapidly
over my django-fu).

Hope this helps,
Tone

tonemcd

unread,
Aug 28, 2008, 1:48:35 PM8/28/08
to Django users
I've just come across this ticket, http://code.djangoproject.com/ticket/8221,
which has a patch attached. I've just applied the patch and crippled
my url regex again to re-create the error. This is what was reported
this time;

NoReverseMatch: Reverse for 'MBBS.agenda_today_group' with arguments
'(u'st4gp4&5',)' and keyword arguments '{}' not found.

Now *that* would have saved a heap of time earlier on today ;)

Ticket 8221 is down for the 1.0 release, so hopefully, we'll have that
in trunk ready for the big release of V1.0.

HTH
Tone

On Aug 28, 6:20 pm, tonemcd <tony.mcdon...@gmail.com> wrote:
> Well, this bit me a while back when I svn-up'ed from trunk and I got
> fed up of changing my django.pth to point to trunk_r7971, so I was
> determined to get it sorted out.
>
> The first thing is that the NoReverseMatch error seems to be a catch-
> all for a variety of exceptions, so if you can, check out your imports
> as Koen outlines below.
>
> However, I think that in this case it is far more likely that you have
> some data that is triggering the NoReverseMatch exception, as you say
> it happens randomly, and I think what is happening is your arguments
> to {% url ... %} are not compatible with what your named url is
> expecting to see.
>
> This is what happened to me; my urls are of the form;
>
> today/<group>/agenda
>
> where <group> is letters (upper and lowercase), numbers and '-', so
> these are valid stgp01, st2gp2-18 etc.
>
> I used this match to begin with;
> url(r'^today/(?P<group>[\w,-]+)/agenda$
>
> fromhttp://python.about.com/od/regularexpressions/a/regexprimer.htm

daniel...@gmail.com

unread,
Sep 12, 2008, 6:07:39 PM9/12/08
to Django users
I had this problem as well. I switched to lighttpd + fast_cgi and
haven't had the problem since.

On 28 Aug, 11:48, tonemcd <tony.mcdon...@gmail.com> wrote:
> I've just come across this ticket,http://code.djangoproject.com/ticket/8221,
Reply all
Reply to author
Forward
0 new messages