From ce76fbfc5a14b0dbfdf28badb4bff874c8286d48 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 10 Mar 2013 23:24:34 +0100 Subject: [PATCH] Fixed #20019 -- Ensured HttpRequest.resolver_match always exists. Obviously it isn't set until the URL is resolved. --- django/http/request.py | 1 + tests/urlpatterns_reverse/tests.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/http/request.py b/django/http/request.py index 2c19e4ee8c..ad18706e1e 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -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): diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index f6da4b2692..8dc21e4bc9 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -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'