Django

Code

Ticket #8358 (closed: fixed)

Opened 11 months ago

Last modified 3 months ago

Test client raises UnboundLocalError when view raises exception and 500.html does not exist.

Reported by: ryan_freckleton Assigned to: nobody
Milestone: 1.0 Component: Testing framework
Version: SVN Keywords: test client exception unboundlocalerror
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If an exception is raised in a view that is requested by the test client and the 500.html template does not exist, the test fails with the following traceback:

Traceback (most recent call last):
  File "/home/ryan/src/django_stuff/client_test/../client_test/test_app/tests.py", line 5, in test
    response = self.client.get('/')
  File "/home/ryan/src/django_stuff/django_py/lib/python2.5/site-packages/django/test/client.py", line 265, in get
    return self.request(**r)
  File "/home/ryan/src/django_stuff/django_py/lib/python2.5/site-packages/django/test/client.py", line 231, in request
    response.client = self
UnboundLocalError: local variable 'response' referenced before assignment

The view function used to generate this was:

def raise_error(request):
    raise Exception()

self.exc_info in the client is not set, so no exception is raised at line client.py:225-228, and an UnboundLocalError? is raised at line 231.

This could possibly be related to issue #8136, but I'm not really sure.

Attachments

Change History

08/16/08 01:37:41 changed by russellm

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

This could be the same cause as #8136, but the reported exception is slightly different; I'll make sure when I get around to fixing the problem.

08/16/08 01:38:28 changed by russellm

  • component changed from Core framework to Unit test system.

08/18/08 21:53:10 changed by ryan_freckleton

I tried the patch associated with #8136 and it seems to fix this error message as well. So it's probably the same root cause.

08/22/08 08:59:49 changed by russellm

  • status changed from new to closed.
  • resolution set to duplicate.

On deeper inspection, this is the same problem as #8136.

04/03/09 13:30:55 changed by jacob

  • resolution changed from duplicate to fixed.

(In [10371]) Fixed a whole bunch of small docs typos, errors, and ommissions.

Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.

Thanks to all the respective authors of those tickets.


Add/Change #8358 (Test client raises UnboundLocalError when view raises exception and 500.html does not exist.)




Change Properties
Action