Render Config fails with DataFile templates using dynamic include statements #10502

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

Originally created by @ed-ud on GitHub (Nov 21, 2024).

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.4

Python Version

3.12

Steps to Reproduce

  1. Create a Data Source with several Jinja2 template files:

start.j2:
{%- set PATH = 'my/prefix/' %}
{%- include PATH + 'test.j2' %}

my/prefix/test.j2:
SOME RENDERED TEXT

  1. Create Config Template using the Data Source and the Data File start.j2
  2. Attach Config Template to a Device
  3. Select the Render Config tab on the Device

Expected Behavior

Should not fail to render.

Observed Behavior

Fails to render with TemplateNotFound 'my/prefix/test.j2' exception.

Originally created by @ed-ud on GitHub (Nov 21, 2024). ### Deployment Type Self-hosted ### Triage priority N/A ### NetBox Version v4.1.4 ### Python Version 3.12 ### Steps to Reproduce 1. Create a Data Source with several Jinja2 template files: start.j2: {%- set PATH = 'my/prefix/' %} {%- include PATH + 'test.j2' %} my/prefix/test.j2: SOME RENDERED TEXT 2. Create Config Template using the Data Source and the Data File start.j2 3. Attach Config Template to a Device 4. Select the Render Config tab on the Device ### Expected Behavior Should not fail to render. ### Observed Behavior Fails to render with TemplateNotFound 'my/prefix/test.j2' exception.
adam added the type: bugstatus: duplicate labels 2025-12-29 21:32:20 +01:00
adam closed this issue 2025-12-29 21:32:20 +01:00
Author
Owner

@ed-ud commented on GitHub (Nov 21, 2024):

A potential fix is to recognize when the Jinja template files are using dynamic includes (the list of referenced_templates contains None entries) and in that case, include all DataFiles from the DataSource.
In utilities/jinja2.py:

diff jinja2.py.orig jinja2.py
32,35c32,41
<             self.cache_templates({
<                 df.path: df.data_as_string for df in
<                 DataFile.objects.filter(source=self.data_source, path__in=referenced_templates)
<             })
---
>             if None in referenced_templates:
>                 self.cache_templates({
>                     df.path: df.data_as_string for df in
>                     DataFile.objects.filter(source=self.data_source)
>                 })
>             else:
>                 self.cache_templates({
>                     df.path: df.data_as_string for df in
>                     DataFile.objects.filter(source=self.data_source, path__in=referenced_templates)
>                 })
@ed-ud commented on GitHub (Nov 21, 2024): A potential fix is to recognize when the Jinja template files are using dynamic includes (the list of referenced_templates contains None entries) and in that case, include all DataFiles from the DataSource. In utilities/jinja2.py: ``` diff jinja2.py.orig jinja2.py 32,35c32,41 < self.cache_templates({ < df.path: df.data_as_string for df in < DataFile.objects.filter(source=self.data_source, path__in=referenced_templates) < }) --- > if None in referenced_templates: > self.cache_templates({ > df.path: df.data_as_string for df in > DataFile.objects.filter(source=self.data_source) > }) > else: > self.cache_templates({ > df.path: df.data_as_string for df in > DataFile.objects.filter(source=self.data_source, path__in=referenced_templates) > }) ```
Author
Owner

@pl0xym0r commented on GitHub (Nov 22, 2024):

same as #17490

@pl0xym0r commented on GitHub (Nov 22, 2024): same as #17490
Author
Owner

@jeremystretch commented on GitHub (Nov 22, 2024):

Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #17490 for further discussion.

@jeremystretch commented on GitHub (Nov 22, 2024): Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #17490 for further discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10502