From 08c60cce3b13f6e60d7588206da2d3c71228f378 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Wed, 14 Apr 2021 14:50:01 +0200 Subject: [PATCH] Fixed #32648 -- Fixed VariableDoesNotExist rendering sitemaps template. --- AUTHORS | 1 + django/contrib/sitemaps/__init__.py | 7 +++---- docs/releases/3.2.1.txt | 3 +++ tests/sitemaps_tests/test_http.py | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 45a593605b..d066c24c56 100644 --- a/AUTHORS +++ b/AUTHORS @@ -94,6 +94,7 @@ answer newbie questions, and generally made Django that much better: Aron Podrigal Artem Gnilov Arthur + Arthur Jovart Arthur Koziel Arthur Rio Arvis Bickovskis diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index b13507a11e..46a54ec8f2 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -168,13 +168,13 @@ class Sitemap: 'lastmod': lastmod, 'changefreq': self._get('changefreq', item), 'priority': str(priority if priority is not None else ''), + 'alternates': [], } if self.i18n and self.alternates: - alternates = [] for lang_code in self._languages(): loc = f'{protocol}://{domain}{self._location(item, lang_code)}' - alternates.append({ + url_info['alternates'].append({ 'location': loc, 'lang_code': lang_code, }) @@ -182,11 +182,10 @@ class Sitemap: lang_code = settings.LANGUAGE_CODE loc = f'{protocol}://{domain}{self._location(item, lang_code)}' loc = loc.replace(f'/{lang_code}/', '/', 1) - alternates.append({ + url_info['alternates'].append({ 'location': loc, 'lang_code': 'x-default', }) - url_info['alternates'] = alternates urls.append(url_info) diff --git a/docs/releases/3.2.1.txt b/docs/releases/3.2.1.txt index d5486f4cc9..4ad9eff5ca 100644 --- a/docs/releases/3.2.1.txt +++ b/docs/releases/3.2.1.txt @@ -30,3 +30,6 @@ Bugfixes * Fixed a regression in Django 3.2 that caused a crash of :attr:`.ModelAdmin.search_fields` when searching against phrases with unbalanced quotes (:ticket:`32649`). + +* Fixed a bug in Django 3.2 where variable lookup errors were logged rendering + the sitemap template if alternates were not defined (:ticket:`32648`). diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index b546c87fe6..fadf88eb60 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -255,9 +255,11 @@ class HTTPSitemapTests(SitemapTestsBase): @override_settings(LANGUAGES=(('en', 'English'), ('pt', 'Portuguese'))) def test_simple_i18n_sitemap_index(self): """ - A simple i18n sitemap index can be rendered. + A simple i18n sitemap index can be rendered, without logging variable + lookup errors. """ - response = self.client.get('/simple/i18n.xml') + with self.assertNoLogs('django.template', 'DEBUG'): + response = self.client.get('/simple/i18n.xml') expected_content = """ {0}/en/i18n/testmodel/{1}/never0.5{0}/pt/i18n/testmodel/{1}/never0.5