Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ed-ud opened this issue Nov 21, 2024 · 3 comments
Closed
Labels
status: duplicate This issue has already been raised type: bug A confirmed report of unexpected behavior in the application

Comments

@ed-ud
Copy link

ed-ud commented 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.

@ed-ud ed-ud added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Nov 21, 2024
@ed-ud
Copy link
Author

ed-ud commented 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)
>                 })

@pl0xym0r
Copy link
Contributor

same as #17490

@jeremystretch
Copy link
Member

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

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
@jeremystretch jeremystretch added status: duplicate This issue has already been raised and removed status: needs triage This issue is awaiting triage by a maintainer labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate This issue has already been raised type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants