Jinja2 template fails to render when it contains include statements #11174

Closed
opened 2025-12-29 21:41:21 +01:00 by adam · 3 comments
Owner

Originally created by @mgades on GitHub (May 14, 2025).

Originally assigned to: @jnovinger on GitHub.

Deployment Type

Self-hosted

NetBox Version

v.4.3.1

Python Version

3.10

Steps to Reproduce

  1. Create two Jinja2 template files ('router/main.j2' and 'common/base.j2'). Content could be empty or random text.
  2. Add a local Data Source (eg. named "netconfig") with the path from the above file locations.
  3. Add 'router/main.j2' as a Configuration Template and attach it to a device (eg. RTR1).
  4. In the 'router/main.j2' file add the following: {%- include 'common/base.j2' %}
  5. Sync the "netconfig" Data Source to update the changes in the file.
  6. Go the the RTR1 device and click the Render Config tab.

Expected Behavior

I would expect the content from 'common/base.j2' to be included in the output on the screen.

It worked fine in v4.2.8 (before upgrading to 4.3.0 and 4.3.1).

Observed Behavior

The complete exception is provided below:

<class 'TypeError'>

no loader for this environment specified

Python version: 3.10.12
NetBox version: 4.3.1
Plugins: None installed

Originally created by @mgades on GitHub (May 14, 2025). Originally assigned to: @jnovinger on GitHub. ### Deployment Type Self-hosted ### NetBox Version v.4.3.1 ### Python Version 3.10 ### Steps to Reproduce 1. Create two Jinja2 template files ('router/main.j2' and 'common/base.j2'). Content could be empty or random text. 2. Add a local Data Source (eg. named "netconfig") with the path from the above file locations. 3. Add 'router/main.j2' as a Configuration Template and attach it to a device (eg. RTR1). 4. In the 'router/main.j2' file add the following: {%- include 'common/base.j2' %} 5. Sync the "netconfig" Data Source to update the changes in the file. 6. Go the the RTR1 device and click the Render Config tab. ### Expected Behavior I would expect the content from 'common/base.j2' to be included in the output on the screen. It worked fine in v4.2.8 (before upgrading to 4.3.0 and 4.3.1). ### Observed Behavior The complete exception is provided below: <class 'TypeError'> no loader for this environment specified Python version: 3.10.12 NetBox version: 4.3.1 Plugins: None installed
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:41:21 +01:00
adam closed this issue 2025-12-29 21:41:21 +01:00
Author
Owner

@dillon-conner commented on GitHub (May 14, 2025):

Also having this issue, same symptoms. Have a github data source for config files with includes/extends.

Issue started with 4.3 upgrade, same template and data source. Persists in 4.3.1 release as of this morning.
Config template render fails with:

netbox-1               | Internal Server Error: /dcim/devices/3/render-config/
netbox-1               | Traceback (most recent call last):
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
netbox-1               |     response = get_response(request)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
netbox-1               |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
netbox-1               |     return self.dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
netbox-1               |     return super().dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/utilities/views.py", line 125, in dispatch
netbox-1               |     return super().dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/utilities/views.py", line 39, in dispatch
netbox-1               |     return super().dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
netbox-1               |     return handler(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/views.py", line 936, in get
netbox-1               |     context = self.get_extra_context(request, instance)
netbox-1               |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/views.py", line 972, in get_extra_context
netbox-1               |     rendered_config = config_template.render(context=context_data)
netbox-1               |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/models/mixins.py", line 134, in render
netbox-1               |     output = render_jinja2(self.template_code, context, env_params)
netbox-1               |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/utilities/jinja2.py", line 59, in render_jinja2
netbox-1               |     return environment.from_string(source=template_code).render(**context)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render
netbox-1               |     self.environment.handle_exception()
netbox-1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception
netbox-1               |     raise rewrite_traceback_stack(source=source)
netbox-1               |   File "<template>", line 1, in top-level template code
netbox-1               | TypeError: no loader for this environment specified

Image

@dillon-conner commented on GitHub (May 14, 2025): Also having this issue, same symptoms. Have a github data source for config files with includes/extends. Issue started with 4.3 upgrade, same template and data source. Persists in 4.3.1 release as of this morning. Config template render fails with: ``` netbox-1 | Internal Server Error: /dcim/devices/3/render-config/ netbox-1 | Traceback (most recent call last): netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner netbox-1 | response = get_response(request) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response netbox-1 | response = wrapped_callback(request, *callback_args, **callback_kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view netbox-1 | return self.dispatch(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch netbox-1 | return super().dispatch(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/utilities/views.py", line 125, in dispatch netbox-1 | return super().dispatch(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/utilities/views.py", line 39, in dispatch netbox-1 | return super().dispatch(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch netbox-1 | return handler(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/extras/views.py", line 936, in get netbox-1 | context = self.get_extra_context(request, instance) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/extras/views.py", line 972, in get_extra_context netbox-1 | rendered_config = config_template.render(context=context_data) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/extras/models/mixins.py", line 134, in render netbox-1 | output = render_jinja2(self.template_code, context, env_params) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/utilities/jinja2.py", line 59, in render_jinja2 netbox-1 | return environment.from_string(source=template_code).render(**context) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render netbox-1 | self.environment.handle_exception() netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception netbox-1 | raise rewrite_traceback_stack(source=source) netbox-1 | File "<template>", line 1, in top-level template code netbox-1 | TypeError: no loader for this environment specified ``` ![Image](https://github.com/user-attachments/assets/aae19835-58f2-44c2-a520-8e479d438578)
Author
Owner

@jnovinger commented on GitHub (May 16, 2025):

Did a little debugging on this, the offending change appears to be after the v4.2.8/v4.2.9 tags and before the v4.3.0-beta1 tag. List of changes: https://github.com/netbox-community/netbox/compare/v4.3.0-beta1...v4.2.8

@jnovinger commented on GitHub (May 16, 2025): Did a little debugging on this, the offending change appears to be after the v4.2.8/v4.2.9 tags and before the v4.3.0-beta1 tag. List of changes: https://github.com/netbox-community/netbox/compare/v4.3.0-beta1...v4.2.8
Author
Owner

@mgades commented on GitHub (May 23, 2025):

Did a little debugging on this, the offending change appears to be after the v4.2.8/v4.2.9 tags and before the v4.3.0-beta1 tag. List of changes: v4.3.0-beta1...v4.2.8

Thanks @jnovinger - please let me know if you need further info from me...

@mgades commented on GitHub (May 23, 2025): > Did a little debugging on this, the offending change appears to be after the v4.2.8/v4.2.9 tags and before the v4.3.0-beta1 tag. List of changes: [v4.3.0-beta1...v4.2.8](https://github.com/netbox-community/netbox/compare/v4.3.0-beta1...v4.2.8) Thanks @jnovinger - please let me know if you need further info from me...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11174