Difference in behaviour for IP-Addresses and primary IP-addresses for custom links #5976

Closed
opened 2025-12-29 19:35:04 +01:00 by adam · 1 comment
Owner

Originally created by @martinum4 on GitHub (Jan 20, 2022).

NetBox version

v3.1.6

Python version

3.7

Steps to Reproduce

Reproducable at demo.netbox.dev

  1. Assign a primary IPv4-Address to a device
  2. Create a custom link with text and link URL http://{{ obj.primary_ip.address[0] }} scoped on content type dcim | device
  3. Navigate to device
  4. notice the link is wrong

Expected Behavior

Similar to #6782 i expected the IP to be displayed/linked without the subnet mask

Observed Behavior

The last octet of the IP-Address is changed to whatever is in contained in the square brackets of obj.primary_ip.address[0], even when you put stuff like "99" in there.

When using obj.primary_ip.address without anything in squared brackets the actual address is displayed, but with subnet mask.

Originally created by @martinum4 on GitHub (Jan 20, 2022). ### NetBox version v3.1.6 ### Python version 3.7 ### Steps to Reproduce Reproducable at demo.netbox.dev 1. Assign a primary IPv4-Address to a device 2. Create a custom link with text and link URL `http://{{ obj.primary_ip.address[0] }}` scoped on content type `dcim | device` 3. Navigate to device 4. notice the link is wrong ### Expected Behavior Similar to #6782 i expected the IP to be displayed/linked without the subnet mask ### Observed Behavior The last octet of the IP-Address is changed to whatever is in contained in the square brackets of `obj.primary_ip.address[0]`, even when you put stuff like "99" in there. When using `obj.primary_ip.address` without anything in squared brackets the actual address is displayed, but with subnet mask.
adam closed this issue 2025-12-29 19:35:04 +01:00
Author
Owner

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

i expected the IP to be displayed/linked without the subnet mask

Your template code is incorrect. obj.primary_ip.address is the netaddr.IPNetwork object. The IP portion of the address is accessed as obj.primary_ip.address.ip.

@jeremystretch commented on GitHub (Jan 20, 2022): > i expected the IP to be displayed/linked without the subnet mask Your template code is incorrect. `obj.primary_ip.address` is the netaddr.IPNetwork object. The IP portion of the address is accessed as `obj.primary_ip.address.ip`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5976