Opened 8 years ago

Closed 8 years ago

#27794 closed Uncategorized (needsinfo)

Fix confusing error messages for broken `context_processors`

Reported by: Elena Williams Owned by:
Component: Error reporting Version: 1.10
Severity: Normal Keywords: errors, context_processors
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If there is something broken about one or many items in context_processors produces the error message:

No module named context_processors

A better error message would say that an item was broken, not that the module doesn't exist (it usually does exist).

Preferably mention which item is broken.

This is confusing when either TEMPLATES['OPTIONS']['context_processors'] or TEMPLATE_CONTEXT_PROCESSORS do exist. Particularly when upgrading or when the context_processors list is quite long.

Can be trivially replicated by starting a new project and adding any syntactically correct, but otherwise broken entry to context_processors list, for example:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'broken.context_processors',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Examples of this having confused users is discussed:
http://stackoverflow.com/questions/32828536/django-no-module-named-context-processors-error-after-reboot
http://stackoverflow.com/questions/38772498/importerror-no-module-named-context-processors

Attachments (1)

Screenshot from 2017-01-30 13-49-26.png (183.9 KB ) - added by Elena Williams 8 years ago.
Screen capture of ImportError "No module named context_processors" in new project.

Download all attachments as: .zip

Change History (4)

by Elena Williams, 8 years ago

Screen capture of ImportError "No module named context_processors" in new project.

comment:1 by Claude Paroz, 8 years ago

Any error message improvement is welcome when it's possible. Did you spot the location in Django where the import swallowed the initial exception?

comment:2 by Tim Graham, 8 years ago

Could you given an example of what you mean by a broken context processor? Do you mean nonexistent?

On Python 3, with an context_processors entry like 'django.core.context_processors.debug' (which I think is the one used to reproduce the screenshot), the error gives the full path which is more helpful: "No module named 'django.core.context_processors'.

Maybe a system check to flag nonexistent context processors would be helpful.

comment:3 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed

Absent further clarification, I think Python 3's error message is enough to debug this more easily.

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