fix: do not render slot tag when extracting fill tags (#786)

* fix: do not render slot tag when extracting fill tags

* refactor: show component path in error message

* docs: update changelog

* refactor: fix tests
This commit is contained in:
Juro Oravec 2024-11-27 17:19:41 +01:00 committed by GitHub
parent 5a23101038
commit dd6d668b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 182 additions and 2 deletions

View file

@ -318,6 +318,67 @@ class ComponentTest(BaseTestCase):
""",
)
@parametrize_context_behavior(["django", "isolated"])
def test_prepends_exceptions_with_component_path(self):
@register("broken")
class Broken(Component):
template: types.django_html = """
{% load component_tags %}
<div> injected: {{ data|safe }} </div>
<main>
{% slot "content" default / %}
</main>
"""
def get_context_data(self):
data = self.inject("my_provide")
data["data1"] # This should raise TypeError
return {"data": data}
@register("provider")
class Provider(Component):
def get_context_data(self, data: Any) -> Any:
return {"data": data}
template: types.django_html = """
{% load component_tags %}
{% provide "my_provide" key="hi" data=data %}
{% slot "content" default / %}
{% endprovide %}
"""
@register("parent")
class Parent(Component):
def get_context_data(self, data: Any) -> Any:
return {"data": data}
template: types.django_html = """
{% load component_tags %}
{% component "provider" data=data %}
{% component "broken" %}
{% slot "content" default / %}
{% endcomponent %}
{% endcomponent %}
"""
@register("root")
class Root(Component):
template: types.django_html = """
{% load component_tags %}
{% component "parent" data=123 %}
{% fill "content" %}
456
{% endfill %}
{% endcomponent %}
"""
with self.assertRaisesMessage(
TypeError,
"An error occured while rendering components Root > parent > provider > broken:\n"
"tuple indices must be integers or slices, not str",
):
Root.render()
class ComponentValidationTest(BaseTestCase):
def test_validate_input_passes(self):