Opened 13 years ago
Closed 11 years ago
#18418 closed Bug (fixed)
Debug doesn't catch exception instead complains views does not exist
Reported by: | yeukhon | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.4 |
Severity: | Normal | Keywords: | debug |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Suppose we have this forms.py:
class SubmitButtonField(forms.Field): # here we write a custom field.... class Editor(forms.Form): script_name = forms.CharField(max_length=60, min_length=1) view_level = forms.ChoiceField(widget=forms.widgets.RadioSelect, choices=VIEW_LEVEL) text_box = forms.CharField(widget=forms.widgets.Textarea, required=False) save_button = forms.SubmitButtonField(required=False) # notice save_button above....
Notice that save_button
has an error. I accidentally added forms.
in the beginning. This is invalid, and Python will raise exception.
However, when we try to visit the page, it complains about myapp.views.view_name
does not exist.
I fired up django shell, and when I import myapp.views
I got this error:
AttributeError: 'module' object has no attribute 'SubmitButtonField'
Django debug page does not really catch this kind of exception. Is this a bug or an enactment-to-be-made?
Change History (4)
comment:1 by , 12 years ago
Description: | modified (diff) |
---|
comment:2 by , 12 years ago
Component: | Uncategorized → Core (URLs) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Indeed, this is raising an AttributeError
, which is caught in django.core.urlresolvers.get_callable()
. A completely different exception is then raised.
Django (generally) shouldn't mask exceptions.
comment:3 by , 11 years ago
How can I reproduce it?
# app18418/forms.py from django import forms class SubmitButtonField(forms.Field): pass class AForm(forms.Form): save_button = forms.SubmitButtonField(required=False) # cat app18418/views.py import app18418.forms def a_view(request): form = app18418.forms.AForm() # app18418/urls.py from django.conf.urls import patterns, include, url from django.contrib import admin urlpatterns = patterns('', url(r'^$', 'app18418.views.a_view', name='home'), )
Visiting / properly raises the exception:
AttributeError at / 'module' object has no attribute 'SubmitButtonField'
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It's already fixed by:
commit 367bfaa5226eaae3278989e63f16063d5cc46cd8 Author: Florian Apolloner <florian@apolloner.eu> Date: Tue Aug 14 21:12:08 2012 +0200 Don't swallow AttributeError in core.urlresolvers.get_callable.
which made its way into 1.5
Replaced the link to a paste site with the actual content, in case the paste site disappears.