From 879be68be43bf849660c2fbd3cd9b7f50e724192 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Wed, 25 Sep 2019 18:27:30 +0200 Subject: [PATCH] utils: do not raise on Django syntax error in templated_url (#34518) --- combo/data/models.py | 6 +++++- tests/test_pages.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/combo/data/models.py b/combo/data/models.py index 4d086c81..da81df4e 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -807,7 +807,11 @@ class TextCell(CellBase): def sub_variadic_url(match): attribute = match.group(1) url = match.group(2) - url = utils.get_templated_url(url, context=context) + try: + url = utils.get_templated_url(url, context=context) + except utils.TemplateError as e: + logger = logging.getLogger(__name__) + logger.warning('error in templated URL (%s): %s' % (url, e)) return '%s="%s"' % (attribute, url) text = re.sub(r'(href|src)="(.*?)"', sub_variadic_url, text) diff --git a/tests/test_pages.py b/tests/test_pages.py index 77020e4f..f44ee179 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -365,3 +365,13 @@ def test_render(app): response = app.get(page.get_online_url()) assert '' in response.text assert 'Combo - foo' in response.text + +def test_render_cell_having_href_template_error(app): + page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0, description="page description") + page.save() + cell = TextCell(page=page, + text='link', + order=0, placeholder='content') + cell.save() + response = app.get(page.get_online_url()) + assert "{{e-service_url}}backoffice/..." in response.text # href not rendered