0
0
mirror of https://github.com/django/django.git synced 2024-11-29 14:46:18 +01:00

Fixed #20019 -- Ensured HttpRequest.resolver_match always exists.

Obviously it isn't set until the URL is resolved.
This commit is contained in:
Aymeric Augustin 2013-03-10 23:24:34 +01:00
parent 7fca4416c7
commit ce76fbfc5a
2 changed files with 6 additions and 1 deletions

View File

@ -44,6 +44,7 @@ class HttpRequest(object):
self.path = ''
self.path_info = ''
self.method = None
self.resolver_match = None
self._post_parse_error = False
def __repr__(self):

View File

@ -9,7 +9,7 @@ from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.core.urlresolvers import (reverse, resolve, get_callable,
get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
RegexURLPattern)
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.http import HttpRequest, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import redirect
from django.test import TestCase
from django.utils import unittest, six
@ -529,6 +529,10 @@ class ResolverMatchTests(TestCase):
resolver_match = response.resolver_match
self.assertEqual(resolver_match.url_name, 'test-resolver-match')
def test_resolver_match_on_request_before_resolution(self):
request = HttpRequest()
self.assertIsNone(request.resolver_match)
class ErroneousViewTests(TestCase):
urls = 'urlpatterns_reverse.erroneous_urls'