From f71b0cf769d9ac582ee3d1a8c33d73dad3a770da Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 3 Oct 2022 10:52:21 +0200 Subject: [PATCH] Refs #32987 -- Relaxed system check for template tag modules with the same name by turning into a warning. Thanks Claude Paroz for the report. Regression in 004b4620f6f4ad87261e149898940f2dcd5757ef. --- django/core/checks/templates.py | 10 +++++----- docs/ref/checks.txt | 3 +++ docs/releases/4.1.2.txt | 3 +++ tests/check_framework/test_templates.py | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/django/core/checks/templates.py b/django/core/checks/templates.py index 692ec98203..681aa1f317 100644 --- a/django/core/checks/templates.py +++ b/django/core/checks/templates.py @@ -4,7 +4,7 @@ from collections import defaultdict from django.conf import settings from django.template.backends.django import get_template_tag_modules -from . import Error, Tags, register +from . import Error, Tags, Warning, register E001 = Error( "You have 'APP_DIRS': True in your TEMPLATES but also specify 'loaders' " @@ -15,7 +15,7 @@ E002 = Error( "'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: {} ({}).", id="templates.E002", ) -E003 = Error( +W003 = Warning( "{} is used for multiple template tag modules: {}", id="templates.E003", ) @@ -63,12 +63,12 @@ def check_for_template_tags_with_the_same_name(app_configs, **kwargs): for library_name, items in libraries.items(): if len(items) > 1: errors.append( - Error( - E003.msg.format( + Warning( + W003.msg.format( repr(library_name), ", ".join(repr(item) for item in sorted(items)), ), - id=E003.id, + id=W003.id, ) ) diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index aa8d5b6d62..f85c90059d 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -553,6 +553,9 @@ configured: :setting:`OPTIONS ` must be a string but got: ``{value}`` (``{type}``). * **templates.E003**:```` is used for multiple template tag modules: + ````. *This check was changed to* ``templates.W003`` *in Django + 4.1.2*. +* **templates.W003**:```` is used for multiple template tag modules: ````. Translation diff --git a/docs/releases/4.1.2.txt b/docs/releases/4.1.2.txt index 498c645920..1dddbf44a0 100644 --- a/docs/releases/4.1.2.txt +++ b/docs/releases/4.1.2.txt @@ -47,3 +47,6 @@ Bugfixes * Reverted caching related managers for ``ForeignKey``, ``ManyToManyField``, and ``GenericRelation`` that caused the incorrect refreshing of related objects (:ticket:`33984`). + +* Relaxed the system check added in Django 4.1 for the same name used for + multiple template tag modules to a warning (:ticket:`32987`). diff --git a/tests/check_framework/test_templates.py b/tests/check_framework/test_templates.py index 439097f1e1..c8a2f83b8a 100644 --- a/tests/check_framework/test_templates.py +++ b/tests/check_framework/test_templates.py @@ -1,10 +1,10 @@ from copy import copy, deepcopy -from django.core.checks import Error +from django.core.checks import Warning from django.core.checks.templates import ( E001, E002, - E003, + W003, check_for_template_tags_with_the_same_name, check_setting_app_dirs_loaders, check_string_if_invalid_is_string, @@ -108,15 +108,15 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.error_same_tags = Error( - E003.msg.format( + cls.warning_same_tags = Warning( + W003.msg.format( "'same_tags'", "'check_framework.template_test_apps.same_tags_app_1." "templatetags.same_tags', " "'check_framework.template_test_apps.same_tags_app_2." "templatetags.same_tags'", ), - id=E003.id, + id=W003.id, ) @staticmethod @@ -139,7 +139,7 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase): def test_template_tags_with_same_name(self): self.assertEqual( check_for_template_tags_with_the_same_name(None), - [self.error_same_tags], + [self.warning_same_tags], ) def test_template_tags_with_same_library_name(self): @@ -155,7 +155,7 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase): ): self.assertEqual( check_for_template_tags_with_the_same_name(None), - [self.error_same_tags], + [self.warning_same_tags], ) @override_settings( @@ -186,15 +186,15 @@ class CheckTemplateTagLibrariesWithSameName(SimpleTestCase): self.assertEqual( check_for_template_tags_with_the_same_name(None), [ - Error( - E003.msg.format( + Warning( + W003.msg.format( "'same_tags'", "'check_framework.template_test_apps.different_tags_app." "templatetags.different_tags', " "'check_framework.template_test_apps.same_tags_app_1." "templatetags.same_tags'", ), - id=E003.id, + id=W003.id, ) ], )