diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2020-12-27 10:23:16 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-12-28 07:31:37 +0100 |
| commit | 89fc144dedc737a79929231438f035b1d4a993c9 (patch) | |
| tree | 1b83c8577f2183f91f5154f60358da94c7682800 | |
| parent | 429d089d0a8fbd400e0c010708df4f0d16218970 (diff) | |
Fixed #27827 -- Used "raise from" when raising InvalidTemplateLibrary exceptions in get_package_libraries().
This change sets the __cause__ attribute to raised exceptions and makes
small cleanups in error messages.
| -rw-r--r-- | django/template/backends/django.py | 2 | ||||
| -rw-r--r-- | tests/template_backends/test_django.py | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/django/template/backends/django.py b/django/template/backends/django.py index 80d11d3cdd..d99631cc19 100644 --- a/django/template/backends/django.py +++ b/django/template/backends/django.py @@ -123,7 +123,7 @@ def get_package_libraries(pkg): raise InvalidTemplateLibrary( "Invalid template library specified. ImportError raised when " "trying to load '%s': %s" % (entry[1], e) - ) + ) from e if hasattr(module, 'register'): yield entry[1] diff --git a/tests/template_backends/test_django.py b/tests/template_backends/test_django.py index 6f5035c741..047af67df5 100644 --- a/tests/template_backends/test_django.py +++ b/tests/template_backends/test_django.py @@ -104,13 +104,14 @@ class DjangoTemplatesTests(TemplateStringsTests): InvalidTemplateLibrary, "ImportError raised when trying to load " "'template_backends.apps.importerror.templatetags.broken_tags'" - ): + ) as cm: DjangoTemplates({ 'DIRS': [], 'APP_DIRS': False, 'NAME': 'django', 'OPTIONS': {}, }) + self.assertIsInstance(cm.exception.__cause__, ImportError) def test_builtins_discovery(self): engine = DjangoTemplates({ |
