Fixed #20019 -- Ensured HttpRequest.resolver_match always exists.
Obviously it isn't set until the URL is resolved.
This commit is contained in:
parent
7fca4416c7
commit
ce76fbfc5a
|
@ -44,6 +44,7 @@ class HttpRequest(object):
|
||||||
self.path = ''
|
self.path = ''
|
||||||
self.path_info = ''
|
self.path_info = ''
|
||||||
self.method = None
|
self.method = None
|
||||||
|
self.resolver_match = None
|
||||||
self._post_parse_error = False
|
self._post_parse_error = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
|
||||||
from django.core.urlresolvers import (reverse, resolve, get_callable,
|
from django.core.urlresolvers import (reverse, resolve, get_callable,
|
||||||
get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
|
get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
|
||||||
RegexURLPattern)
|
RegexURLPattern)
|
||||||
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
from django.http import HttpRequest, HttpResponseRedirect, HttpResponsePermanentRedirect
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import unittest, six
|
from django.utils import unittest, six
|
||||||
|
@ -529,6 +529,10 @@ class ResolverMatchTests(TestCase):
|
||||||
resolver_match = response.resolver_match
|
resolver_match = response.resolver_match
|
||||||
self.assertEqual(resolver_match.url_name, 'test-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):
|
class ErroneousViewTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.erroneous_urls'
|
urls = 'urlpatterns_reverse.erroneous_urls'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue