Opened 5 years ago

Last modified 5 years ago

#30728 closed Bug

Django urls patterns resolver shadowing exceptions thrown everywhere else — at Version 1

Reported by: Ariel Torti Owned by: nobody
Component: Utilities Version: 2.2
Severity: Release blocker Keywords:
Cc: Tom Forbes 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 Ariel Torti)

The new version of django somehow captures all the exceptions ocurred while parsing the urlpatterns.

How to reproduce:

  • Create a django project
  • Create a an app

app/views.py

from django.shortcuts import render

class MyCustomExceptionShadowed(Exception):
  pass

raise MyCustomExceptionShadowed('I have a description of your error')

# Create your views here.
def myview(request):
  pass

urls.py

from django.contrib import admin
from django.urls import path

from bugtest import views

urlpatterns = [
    path('', views.myview),
    path('admin/', admin.site.urls),
]

When running the server I get

django.core.exceptions.ImproperlyConfigured: The included URLconf 'bug.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

When in fact I expect it to say

  File "/home/ariel-nt/Desktop/test/bug/bugtest/views.py", line 6, in <module>
    raise MyCustomExceptionShadowed('I have a description of your error')
bugtest.views.MyCustomExceptionShadowed: I have a description of your error

I tested this with django 2.1 and it works as expected, so I'll now try to find the root cause of the error and give an update here
The issue in introduced in this commit https://github.com/django/django/commit/097457afe47e50e76d53b1cd3312ba8364f866cb#diff-46e69f287173eef41fcbfeba05501954R274
This line https://github.com/django/django/blob/097457afe47e50e76d53b1cd3312ba8364f866cb/django/utils/autoreload.py#L274 absorbs all the exceptions not showing them to the developer.

Change History (1)

comment:1 by Ariel Torti, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top