diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py index 9d071933ed..5d2745e267 100644 --- a/wagtail/admin/templatetags/wagtailadmin_tags.py +++ b/wagtail/admin/templatetags/wagtailadmin_tags.py @@ -739,7 +739,10 @@ def component(context, obj, fallback_render_method=False): # called instead (with no arguments) - this is to provide deprecation path for things that have # been newly upgraded to use the component pattern. - if fallback_render_method and not hasattr(obj, 'render_html') and hasattr(obj, 'render'): + has_render_html_method = hasattr(obj, 'render_html') + if fallback_render_method and not has_render_html_method and hasattr(obj, 'render'): return obj.render() + elif not has_render_html_method: + raise ValueError("Cannot render %r as a component" % (obj,)) return obj.render_html(context) diff --git a/wagtail/admin/tests/test_templatetags.py b/wagtail/admin/tests/test_templatetags.py index c89bcd334b..96aaafed07 100644 --- a/wagtail/admin/tests/test_templatetags.py +++ b/wagtail/admin/tests/test_templatetags.py @@ -149,3 +149,12 @@ class TestComponentTag(TestCase): ) html = template.render(Context({'my_component': MyComponent()})) self.assertEqual(html, "

Look, I'm running with scissors! 8< 8< 8<

") + + def test_error_on_rendering_non_component(self): + template = Template( + "{% load wagtailadmin_tags %}

{% component my_component %}

" + ) + + with self.assertRaises(ValueError) as cm: + template.render(Context({'my_component': "hello"})) + self.assertEqual(str(cm.exception), "Cannot render 'hello' as a component")