Code

Opened 23 months ago

Closed 2 months 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 aaugustin)

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?

Attachments (0)

Change History (4)

comment:1 Changed 22 months ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Replaced the link to a paste site with the actual content, in case the paste site disappears.

Last edited 22 months ago by aaugustin (previous) (diff)

comment:2 Changed 22 months ago by aaugustin

  • Component changed from Uncategorized to Core (URLs)
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to 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 Changed 2 months ago by gnosek

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 Changed 2 months ago by gnosek

  • Resolution set to fixed
  • Status changed from new to 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.