-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
approvedIssue has been approved by the bot or manually for further processingIssue has been approved by the bot or manually for further processingbugIssue describes a bugIssue describes a bugdoneDone but not yet releasedDone but not yet released
Milestone
Description
Problem
Discovered here: cp2004/OctoPrint-CameraStreamer-Control#9
Third party plugins not opted into autoescaping are wrapped inside a
{% autoescape false %}
...
{% endautoescape %}
block here:
OctoPrint/src/octoprint/server/__init__.py
Lines 1214 to 1226 in 3f45e66
if PluginFlags.AUTOESCAPE_ON not in plugin._plugin_info.flags and ( | |
PluginFlags.AUTOESCAPE_OFF in plugin._plugin_info.flags | |
or ( | |
not plugin._plugin_info.bundled | |
and not plugin.is_template_autoescaped() | |
) | |
): | |
loader = octoprint.util.jinja.PostProcessWrapperLoader( | |
loader, | |
lambda source: "{% autoescape false %}" | |
+ source | |
+ "{% endautoescape %}", | |
) |
This somehow seems to break macros insides those third party plugins. E.g. this piece of jinja code:
{% import "macros.jinja2" as macros %}
// ...
<label class="control-label" for="{{ macros.id("mode") }}">Preferred Video Mode</label>
leads to an error like this:
2025-01-30 10:25:12,823 - octoprint.util.jinja - ERROR - Caught exception while compiling template tabs/control.jinja2 at line 14
Traceback (most recent call last):
File "/home/gina/devel/OctoPrint/OctoPrint/src/octoprint/util/jinja.py", line 258, in _handle_body
return caller()
^^^^^^^^
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/runtime.py", line 770, in __call__
return self._invoke(arguments, autoescape)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/runtime.py", line 784, in _invoke
rv = self._func(*arguments)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/gina/devel/OctoPrint/OctoPrint/src/octoprint/templates/tabs/control.jinja2", line 89, in macro
</div>
File "/home/gina/devel/OctoPrint/OctoPrint-CameraStreamer-Control/octoprint_camerastreamer_control/templates/camerastreamer_control_webcam.jinja2", line 18, in root
File "/home/gina/devel/OctoPrint/OctoPrint-CameraStreamer-Control/octoprint_camerastreamer_control/templates/modes/mjpg.jinja2", line 17, in root
<p>
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/runtime.py", line 284, in call
pass_arg = _PassArg.from_obj(__obj)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/utils.py", line 92, in from_obj
if hasattr(obj, "jinja_pass_arg"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/runtime.py", line 870, in __getattr__
return self._fail_with_undefined_error()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gina/.pyenv/versions/3.11.2/envs/octoprint-py311/lib/python3.11/site-packages/jinja2/runtime.py", line 859, in _fail_with_undefined_error
raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'jinja2.environment.TemplateModule object' has no attribute 'id'
For some reason, the id
property is not available on the imported macros template.
Disabling autoescape and removing the wrapper makes things work again.
Solution
TBD, Investigating...
Metadata
Metadata
Assignees
Labels
approvedIssue has been approved by the bot or manually for further processingIssue has been approved by the bot or manually for further processingbugIssue describes a bugIssue describes a bugdoneDone but not yet releasedDone but not yet released
Type
Projects
Status
Done