views:

146

answers:

2

We recently launched a new Django-powered website, and we are experiencing the oddest bug:

The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "".

We haven't noticed anything in Apache's log file; there are no errors being generated by Django. And (the kicker) the problem only occurs in production mode; we can't reproduce it when DEBUG=True.

Any thoughts on where we should be looking for the problem?

Update: It turned out to be a problem with settings.LANGUAGES, although we haven't determined exactly why that broke things.

+2  A: 

Django has a odd behaviour when matching urls in a environment that isn't under debug mode.

For example, with DEBUG=False, Django will ignore urls such as:

url(r'^', include('someapp.urls')),

specifically in the case above, you could let the string empty:

url(r'', include('someapp.urls')),

In other words, check your regexes.

Can you put your urls.py here to be analyzed?

Gabriel Falcão
+5  A: 

This has happened to me before. Normally it's due to a 'broken' urls.py file. There are two things that make this kind of bug really hard to fix:

  • It could be the urls.py file in any of the apps that breaks the reverse() function, so knowing that reverse() breaks for app X doesn't mean the error is in that particular application's urls.py.
  • Django won't even notify you of errors in the urls.py file, unless you somehow manage to crash the site by doing something really, really nasty in the urls.py file.

Debugging: The way I go around fixing this is by manually disabling all applications (just comment out their line in INSTALLED_APPS) and checking reverse() works. If it still works, then I enable the next app, until it breaks. I know, very rudimentary stuff, but it works :)

dguaraglia