Skip to content

Commit 04e87e7

Browse files
committed
Refs #31877 -- Reverted "Fixes #31877 -- Used lazy() for TemplateView kwarg deprecation warning."
This reverts commit 20799cc.
1 parent b5acb9d commit 04e87e7

File tree

3 files changed

+5
-26
lines changed

3 files changed

+5
-26
lines changed

django/views/generic/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.urls import reverse
1212
from django.utils.decorators import classonlymethod
1313
from django.utils.deprecation import RemovedInDjango40Warning
14-
from django.utils.functional import lazy
14+
from django.utils.functional import SimpleLazyObject
1515

1616
logger = logging.getLogger('django.request')
1717

@@ -169,6 +169,7 @@ def _wrap_url_kwargs_with_deprecation_warning(url_kwargs):
169169
context_kwargs = {}
170170
for key, value in url_kwargs.items():
171171
# Bind into function closure.
172+
@SimpleLazyObject
172173
def access_value(key=key, value=value):
173174
warnings.warn(
174175
'TemplateView passing URL kwargs to the context is '
@@ -177,7 +178,7 @@ def access_value(key=key, value=value):
177178
RemovedInDjango40Warning, stacklevel=2,
178179
)
179180
return value
180-
context_kwargs[key] = lazy(access_value, type(value))()
181+
context_kwargs[key] = access_value
181182
return context_kwargs
182183

183184

docs/releases/3.1.1.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ Bugfixes
2626
related fields pointing to a proxy model in the ``of`` argument, the
2727
corresponding model was not locked (:ticket:`31866`).
2828

29-
* Fixed a regression in Django 3.1 that caused a crash when passing deprecated
30-
keyword arguments to a queryset in ``TemplateView.get_context_data()``
31-
(:ticket:`31877`).
32-
3329
* Fixed a data loss possibility, following a regression in Django 2.0, when
3430
copying model instances with a cached fields value (:ticket:`31863`).
3531

tests/generic_views/test_base.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
from django.core.exceptions import ImproperlyConfigured
44
from django.http import HttpResponse
55
from django.test import (
6-
RequestFactory, SimpleTestCase, TestCase, ignore_warnings,
7-
override_settings,
6+
RequestFactory, SimpleTestCase, ignore_warnings, override_settings,
87
)
98
from django.test.utils import require_jinja2
109
from django.urls import resolve
1110
from django.utils.deprecation import RemovedInDjango40Warning
1211
from django.views.generic import RedirectView, TemplateView, View
1312

1413
from . import views
15-
from .models import Artist
1614

1715

1816
class SimpleView(View):
@@ -573,9 +571,7 @@ def test_template_mixin_without_template(self):
573571

574572

575573
@override_settings(ROOT_URLCONF='generic_views.urls')
576-
class DeprecationTests(TestCase):
577-
rf = RequestFactory()
578-
574+
class DeprecationTests(SimpleTestCase):
579575
@ignore_warnings(category=RemovedInDjango40Warning)
580576
def test_template_params(self):
581577
"""A generic template view passes kwargs as context."""
@@ -607,17 +603,3 @@ def test_template_params_warning(self):
607603
str(response.context['foo2'])
608604
self.assertEqual(response.context['key'], 'value')
609605
self.assertIsInstance(response.context['view'], View)
610-
611-
@ignore_warnings(category=RemovedInDjango40Warning)
612-
def test_template_params_filtering(self):
613-
class ArtistView(TemplateView):
614-
template_name = 'generic_views/about.html'
615-
616-
def get_context_data(self, *, artist_name, **kwargs):
617-
context = super().get_context_data(**kwargs)
618-
artist = Artist.objects.get(name=artist_name)
619-
return {**context, 'artist': artist}
620-
621-
artist = Artist.objects.create(name='Rene Magritte')
622-
response = ArtistView.as_view()(self.rf.get('/'), artist_name=artist.name)
623-
self.assertEqual(response.context_data['artist'], artist)

0 commit comments

Comments
 (0)