Skip to content

Commit

Permalink
Merge pull request #1059 from benjaoming/fix-checks-load-templatetags
Browse files Browse the repository at this point in the history
Soften a check failure
  • Loading branch information
benjaoming committed Jul 10, 2020
2 parents 3cd541e + 2b286fe commit 523bc08
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
9 changes: 9 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -13,6 +13,15 @@ Release plan
* **0.7.x** Milestone TBA


0.6.1.dev
---------

Fixed
~~~~~

* Do not fail prematurely during Django checks framework (rare issue) :url-issue:`1059` (Benjamin Bach)


0.6
---

Expand Down
31 changes: 22 additions & 9 deletions src/wiki/checks.py
Expand Up @@ -64,16 +64,29 @@ def check_for_obsolete_installed_apps(app_configs, **kwargs):

def check_for_context_processors(app_configs, **kwargs):
errors = []
context_processors = Engine.get_default().context_processors
for context_processor in REQUIRED_CONTEXT_PROCESSORS:
if context_processor[0] not in context_processors:
errors.append(
Error(
"needs %s in TEMPLATE['OPTIONS']['context_processors']"
% context_processor[0],
id="wiki.%s" % context_processor[1],
# Pattern from django.contrib.admin.checks
try:
default_template_engine = Engine.get_default()
except Exception:
# Skip this non-critical check:
# 1. if the user has a non-trivial TEMPLATES setting and Django
# can't find a default template engine
# 2. if anything goes wrong while loading template engines, in
# order to avoid raising an exception from a confusing location
# Catching ImproperlyConfigured suffices for 1. but 2. requires
# catching all exceptions.
pass
else:
context_processors = default_template_engine.context_processors
for context_processor in REQUIRED_CONTEXT_PROCESSORS:
if context_processor[0] not in context_processors:
errors.append(
Error(
"needs %s in TEMPLATES[*]['OPTIONS']['context_processors']"
% context_processor[0],
id="wiki.%s" % context_processor[1],
)
)
)
return errors


Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_checks.py
Expand Up @@ -38,7 +38,7 @@ def test_required_context_processors(self):
errors = registry.run_checks(tags=[Tags.context_processors])
expected_errors = [
Error(
"needs %s in TEMPLATE['OPTIONS']['context_processors']"
"needs %s in TEMPLATES[*]['OPTIONS']['context_processors']"
% context_processor[0],
id="wiki.%s" % context_processor[1],
)
Expand Down

0 comments on commit 523bc08

Please sign in to comment.