Context Navigation

Better Error Messages

Good error messages make for more productive developers. This page is a place to collect error messages that could stand improvement, or which are misleading or confusing in certain contexts. Most of us have had the experience of getting a "weird" message, puzzling it out (perhaps with help from django-users or #django) and then moving on.

Some of these may seem like quick patches but others will take a bit of consideration -- that's why the wiki page rather than individual tickets. Some are more along the lines of "Django Lint" than simple changes to error output.

For now, let's try dividing them into sections by major module. Within those sections suggested format is: error message, explanatory context (often important -- a message that is very helpful in one context can be confusing in another), suggested improvements/changes.

django.contrib.admin

'NoneType' object has no attribute 'get_field_sets'

Context: One or more models that are referenced by ForeignKey from another model are missing their inner Admin class. Possible other causes as well. See ticket #1808. Suggestion: Check relevant Admin settings during model validation?

Context: This error may appear on the admin screen after trying to save a form, even though there is no error below that is highlighted. Suggestion: Check to see if you have listed the desired fields in ModelAdmin, but then misspelled one while trying to use a custom form field in an associated ModelForm.

django.core

TypeError at ...
string indices must be integers

Context: A FileUploadField is being validated but the form did not have enctype="multipart/form-data" set.Suggestion: Check form enctype during validation? Show FILES in addition to GET and POST on error pages?

Context: You get only this error line starting the developer server. But this doesn't help to find the real error.Suggestion: e.g. one model can't import because you have a import loop. Use the patch from Ticket #11667 to get a full traceback and bugfix your models.

ProgrammingError: ERROR: current transaction is aborted, commands ignored until end of transaction block

​http://bit.ly/UXJ87l​http://bit.ly/10jCXxd
This pyscopg2 (PostgreSQL) error usually signifies that some previous database query was incorrect (e.g., you tried to order_by() a field that doesn't exist, or put a string in an integer column, etc.). That previous error aborted the transaction, causing all subsequent database access to fail with this message.

If you get this while at a shell, you can fix your database connection by executing a rollback:

If you get this from a view, it probably means the immediately previous query had a problem (but was caught by an over-eager exception handler).

In certain situations with PostgreSQL, a bogus error message about SET TIME ZONE may be returned. See #3179 (which is closed, but has a description of the problem). The real error message can probably be found in the postgres log file.

DoesNotExist: %s matching query does not exist

It would be really helpful for the error message to state what the query was, for example:

django.forms

If you create a ModelForm but neglect to indicate the model in the Meta, you get:

TypeError: 'NoneType' object is not callable

In django.forms.models line 240 there could be a check to make sure the options instance has a valid model declaration and if not warn the user more explicitly ("ModelForm <classname> does is missing the model")
This is covered by #12285.

#15126 describes a common class of problem -- users with a single-item tuple forgetting the trailing comma. This was reported in the context of ModelForm.fields, but is a general problem that can (and should) be caught and reported.

django.http

AttributeError: Http404 instance has no attribute 'has_header'

Context: Http404 is returned instead of raisedSuggestion: Check type of HttpResponse before attempting to use (perhaps unPythonic?) or possibly give Http404 a clearer name like Http404Exception

django.shortcuts

Invoking .render() with a <coconut> object instead of a HttpRequest as the first argument invokes AttributeError with the message: "'<coconut>' object has no attribute 'META'". Better will be something like, "render() takes a request object for the first argument."

What seems to be happening is that self.invalid_block_tag(...) raises an error which gets caught by TemplateSyntaxError and which eventually leads to the generic 'list index out of range' error being reported in the Django error page.