resolve_component finds wrong app if extended base template is in another app
Closed this issue · 3 comments
This line gets the template of the component. I suppose in most cases this is working, but here I have a component which is in the "homepage" app, and the template which uses the component extends a base template which is in the "core" app.
While debugging the tetra code, I found that context.render_context.template.origin.name
is "core", and context.template.origin.name
is (the correct) "homepage".
So I think that the *render_context" is not necessary - at least when I remove it, it works properly.
So the line should be:
template = context.template
Please tell mi if I should make a PR. But as there are no tests, I can't test further. It works perfectly for me here.
Definitely tested again. Tetra seems to assume that the base template (in my case "html.html" that is in app A and that is extended in app B) contains the component.
So if a component is defined in B's template:
{% extends "A/html.html" %}
{% block content %}
{% @ foo / %}
{% endblock %}
It seems that Tetra finds the base template and uses that as the component's app_config.
So, really, it finds A's foo component where it should find B's component.
I can test that by declaring the Foo component in A and B apps with different content.
This is correctly resolved when instead of context.render_context.template
just context.template
is used.
I triple-checked with all combinations, but this seems to be the fix.
The error is simple and has nothing to do with the finding algorithm. Just to write it down, if we don't find it later:
In
tetra/tetra/component_register.py
Line 29 in d52f384
E.g. when the module imports another module that is not installed, it will be silently ignored, no cascaded ModuleNotFoundError will be raised.
This is e.g. if the sourcetypes module is not installed in the demo run. All the demo components are just vanished, and no error message shows up.
I added a logging error when the ModuleNotFoundError exception is triggered. So at least on the server log output something is displayed as help.