Config Render crashes netbox #10655

Closed
opened 2025-12-29 21:34:13 +01:00 by adam · 8 comments
Owner

Originally created by @ITTV-tools on GitHub (Jan 16, 2025).

Deployment Type

Self-hosted

Triage priority

I volunteer to perform this work (if approved)

NetBox Version

4.2.1

Python Version

3.12

Steps to Reproduce

Create an device with an template

{% for interface in device.interfaces.all() %}
{%- if interface.mgmt_only == false %}
interface {{ interface.name }}
{%- if interface.description %}
description {{interface.description}}
{%- endif%}
{%- if interface.enabled == false %}
shutdown 
{%- elif interface.enabled == true %} 
no shutdown 
{%- endif%}
{%- if not interface.name.startswith('Vlan') %} 
{%- if interface.mode == "access" %}
switchport mode access
switchport nonegotiate
snmp trap mac-notification change added
snmp trap mac-notification change removed
{%- if device.dot1x %}
access-session control-direction in
access-session closed
access-session port-control auto
dot1x pae authenticator
service-policy type control subscriber POLICY_Access-Interfaces
{%- endif %}
{%- if interface.untagged_vlan %}
switchport access vlan {{ interface.untagged_vlan.vid }}
{%- endif %}
spanning-tree portfast
spanning-tree guard root
{%- elif interface.mode == "tagged" %} 
switchport mode trunk
switchport nonegotiate 
{%- if interface.untagged_vlan %}
switchport trunk nativ vlan {{ interface.untagged_vlan.vid }}
{%- endif %}
{%- for vlan in interface.tagged_vlans.all() %} 
switchport trunk allowed vlan add {{vlan.vid }} 
{%- endfor %} 
{%- elif "tagged-all" in interface.mode %}
{%- if "Access Point" in interface.tags.names() %}
snmp trap mac-notification change added
snmp trap mac-notification change removed
{%- endif %}
switchport mode trunk
switchport nonegotiate 
switchport trunk allowed vlan all
{%- if interface.untagged_vlan %}
switchport trunk nativ vlan {{ interface.untagged_vlan.vid }}
{%- endif %} 
{%- else %} 
{%-if interface.lag != None %} 
channel-group {% for char in interface.lag.name %}{%- if char.isdigit() %}{{ char }}{%- endif %}
{%-endfor %} mode on
{%- endif%} 
{%- endif %} 
{%- endif %}
{%- endif %} 
{%- if interface.ip_addresses.all() %}
{%- for ip in interface.ip_addresses.all() %}
ip address {{ ip.address.ip}} {{ ip.address.netmask }}
{%- endfor %}
 no ip route-cache
{%- endif %}
!
{%- endfor %}

Expected Behavior

Config should render, as it has in version: 4.1.7

Observed Behavior

Netbox crashes:

TypeError at /dcim/devices/55/render-config/

argument of type 'NoneType' is not iterable
Request Method: GET
http:///dcim/devices/55/render-config/
5.1.4
TypeError
argument of type 'NoneType' is not iterable
, line 226, in top-level template code dcim.views.DeviceRenderConfigView /opt/netbox/venv/bin/python 3.12.3 ['/opt/netbox/netbox/', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/opt/netbox/venv/lib/python3.12/site-packages'] Thu, 16 Jan 2025 10:02:34 +0000
Originally created by @ITTV-tools on GitHub (Jan 16, 2025). ### Deployment Type Self-hosted ### Triage priority I volunteer to perform this work (if approved) ### NetBox Version 4.2.1 ### Python Version 3.12 ### Steps to Reproduce Create an device with an template ``` {% for interface in device.interfaces.all() %} {%- if interface.mgmt_only == false %} interface {{ interface.name }} {%- if interface.description %} description {{interface.description}} {%- endif%} {%- if interface.enabled == false %} shutdown {%- elif interface.enabled == true %} no shutdown {%- endif%} {%- if not interface.name.startswith('Vlan') %} {%- if interface.mode == "access" %} switchport mode access switchport nonegotiate snmp trap mac-notification change added snmp trap mac-notification change removed {%- if device.dot1x %} access-session control-direction in access-session closed access-session port-control auto dot1x pae authenticator service-policy type control subscriber POLICY_Access-Interfaces {%- endif %} {%- if interface.untagged_vlan %} switchport access vlan {{ interface.untagged_vlan.vid }} {%- endif %} spanning-tree portfast spanning-tree guard root {%- elif interface.mode == "tagged" %} switchport mode trunk switchport nonegotiate {%- if interface.untagged_vlan %} switchport trunk nativ vlan {{ interface.untagged_vlan.vid }} {%- endif %} {%- for vlan in interface.tagged_vlans.all() %} switchport trunk allowed vlan add {{vlan.vid }} {%- endfor %} {%- elif "tagged-all" in interface.mode %} {%- if "Access Point" in interface.tags.names() %} snmp trap mac-notification change added snmp trap mac-notification change removed {%- endif %} switchport mode trunk switchport nonegotiate switchport trunk allowed vlan all {%- if interface.untagged_vlan %} switchport trunk nativ vlan {{ interface.untagged_vlan.vid }} {%- endif %} {%- else %} {%-if interface.lag != None %} channel-group {% for char in interface.lag.name %}{%- if char.isdigit() %}{{ char }}{%- endif %} {%-endfor %} mode on {%- endif%} {%- endif %} {%- endif %} {%- endif %} {%- if interface.ip_addresses.all() %} {%- for ip in interface.ip_addresses.all() %} ip address {{ ip.address.ip}} {{ ip.address.netmask }} {%- endfor %} no ip route-cache {%- endif %} ! {%- endfor %} ``` ### Expected Behavior Config should render, as it has in version: 4.1.7 ### Observed Behavior Netbox crashes: <h1>TypeError at /dcim/devices/55/render-config/</h1> <pre class="exception_value">argument of type 'NoneType' is not iterable</pre> Request Method: | GET -- | -- http://<domain>/dcim/devices/55/render-config/ 5.1.4 TypeError argument of type 'NoneType' is not iterable <template>, line 226, in top-level template code dcim.views.DeviceRenderConfigView /opt/netbox/venv/bin/python 3.12.3 ['/opt/netbox/netbox/', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/opt/netbox/venv/lib/python3.12/site-packages'] Thu, 16 Jan 2025 10:02:34 +0000
adam closed this issue 2025-12-29 21:34:13 +01:00
Author
Owner

@DanSheps commented on GitHub (Jan 16, 2025):

So it does appear the reverse manager is not being set. This is likely an undocumented upstream change but I am not 100% sure. Still looking into it.

@DanSheps commented on GitHub (Jan 16, 2025): So it does appear the reverse manager is not being set. This is likely an undocumented upstream change but I am not 100% sure. Still looking into it.
Author
Owner

@jeremystretch commented on GitHub (Jan 17, 2025):

@ITTV-tools please reduce the example template to the minimum amount of logic required to reproduce the bug. This will ease troubleshooting efforts.

@jeremystretch commented on GitHub (Jan 17, 2025): @ITTV-tools please reduce the example template to the minimum amount of logic required to reproduce the bug. This will ease troubleshooting efforts.
Author
Owner

@ITTV-tools commented on GitHub (Jan 20, 2025):

The Error Message say Line 226. That is {%- elif "tagged-all" in interface.mode %}
I will try to reproduce it, using only this line

@ITTV-tools commented on GitHub (Jan 20, 2025): The Error Message say Line 226. That is ``{%- elif "tagged-all" in interface.mode %}`` I will try to reproduce it, using only this line
Author
Owner

@ITTV-tools commented on GitHub (Jan 20, 2025):

{% for interface in device.interfaces.all() %}

{%- if "tagged-all" in interface.mode %}
test
{%- endif %}

{%- endfor %}

Results in a crash.

@ITTV-tools commented on GitHub (Jan 20, 2025): ``` {% for interface in device.interfaces.all() %} {%- if "tagged-all" in interface.mode %} test {%- endif %} {%- endfor %} ``` Results in a crash.
Author
Owner

@ITTV-tools commented on GitHub (Jan 20, 2025):

Image
Maybe because there are new options now

@ITTV-tools commented on GitHub (Jan 20, 2025): ![Image](https://github.com/user-attachments/assets/4f834e6e-c16d-4ada-9849-04de7a375933) Maybe because there are new options now
Author
Owner

@DanSheps commented on GitHub (Jan 20, 2025):

Is the crash on "Line 3" or "Line 1"? The error seems to indicate it is more related to your loop (not iterable" instead of the if statement itself.

That said, you are probably better to do a direct compare interface.mode == "tagged-all" as in is typically not used to check in this manner.

@DanSheps commented on GitHub (Jan 20, 2025): Is the crash on "Line 3" or "Line 1"? The error seems to indicate it is more related to your loop (not iterable" instead of the if statement itself. That said, you are probably better to do a direct compare `interface.mode == "tagged-all"` as `in` is typically not used to check in this manner.
Author
Owner

@ITTV-tools commented on GitHub (Jan 20, 2025):

Crash on Line 3.
But interface.mode == "tagged-all" did the trick!
It now works again ! Thanks

@ITTV-tools commented on GitHub (Jan 20, 2025): Crash on Line 3. But ``interface.mode == "tagged-all"`` did the trick! It now works again ! Thanks
Author
Owner

@jeremystretch commented on GitHub (Jan 20, 2025):

This was not a bug in NetBox. Please remember to start a discussion for help with things like export templates unless you can positively confirm that bug exists.

@jeremystretch commented on GitHub (Jan 20, 2025): This was not a bug in NetBox. Please remember to start a [discussion](https://github.com/netbox-community/netbox/discussions/new/choose) for help with things like export templates unless you can positively confirm that bug exists.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10655