Skip to content

Commit d99a5a4

Browse files
committed
Catch errors on startup
1 parent 204e57a commit d99a5a4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

djangocms_frontend/component_pool.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ def scan_templates_for_component_declaration(self, templates: list[tuple[str, st
7777
components = []
7878
field_context = self.get_field_context()
7979
for module, template_name in templates:
80+
# Create a new context for each template
8081
context = {"_cms_components": defaultdict(list), "forms": fields, "instance": {}, **field_context}
81-
loader.render_to_string(template_name, context)
82-
cms_component = context["_cms_components"].get("cms_component", [])
83-
fields = context["_cms_components"].get("fields", [])
84-
if len(cms_component) == 1:
85-
components.append(self.component_factory(module, cms_component[0], fields, template_name))
86-
elif len(cms_component) > 1: # pragma: no cover
87-
raise ValueError(f"Multiple cms_component tags found in {template_name}")
82+
try:
83+
loader.render_to_string(template_name, context)
84+
cms_component = context["_cms_components"].get("cms_component", [])
85+
fields = context["_cms_components"].get("fields", [])
86+
if len(cms_component) == 1:
87+
components.append(self.component_factory(module, cms_component[0], fields, template_name))
88+
elif len(cms_component) > 1: # pragma: no cover
89+
raise ValueError(f"Multiple cms_component tags found in {template_name}")
90+
except Exception: # pragma: no cover
91+
# Skip all templates that do not render
92+
import logging
93+
94+
logger = logging.getLogger(__name__)
95+
logger.error(f"Error rendering template {template_name} to scan for cms frontend components", exc_info=True)
96+
pass
8897
return components
8998

9099

tests/requirements/base.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
coverage
2-
django-app-helper
32
tox
43
coverage
54
isort

0 commit comments

Comments
 (0)