Adding IP address to device after deleting primary IP address fails due to caching #3691

Closed
opened 2025-12-29 18:30:38 +01:00 by adam · 0 comments
Owner

Originally created by @lampwins on GitHub (May 15, 2020).

Originally assigned to: @lampwins on GitHub.

Environment

  • Python version: 3.7
  • NetBox version: 2.8.4

Steps to Reproduce

  1. Disable any installed plugins by commenting out the PLUGINS setting in
    configuration.py.
  2. Create a device
  3. Create an interface on that device
  4. Add a new IP address to the interface and set it as the primary
  5. Delete the primary IP address
  6. Add a new IP address to the interface but do not set it as the primary

Expected Behavior

The new, non-primary address to be added to the interface and to be redirected back to the device page.

Observed Behavior

The IP address is created and assigned to the interface but the request fails, stating the old primary IP address cannot be found.

This is due to a caching invalidation bug that was uncovered when fixing #3304. The internals of the IPAddressForm.save() method makes use of the interface's parent attribute to access the primary_ip4/ip6 attributes. This issue is the access to that attribute crosses a FK relation which is not linked by cacheops for invalidation. This is very similar to the root cause described in #3304 and the fix is equally similar.

This highlights again that we need to make sure we are using prefetch_related() for all FK relationships to ensure invalidation linking for SET_NULL conditions.

Originally created by @lampwins on GitHub (May 15, 2020). Originally assigned to: @lampwins on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.7 * NetBox version: 2.8.4 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Disable any installed plugins by commenting out the `PLUGINS` setting in `configuration.py`. 2. Create a device 3. Create an interface on that device 4. Add a new IP address to the interface and set it as the primary 5. Delete the primary IP address 6. Add a new IP address to the interface but do *not* set it as the primary <!-- What did you expect to happen? --> ### Expected Behavior The new, non-primary address to be added to the interface and to be redirected back to the device page. <!-- What happened instead? --> ### Observed Behavior The IP address is created and assigned to the interface but the request fails, stating the old primary IP address cannot be found. This is due to a caching invalidation bug that was uncovered when fixing #3304. The internals of the IPAddressForm.save() method makes use of the interface's parent attribute to access the primary_ip4/ip6 attributes. This issue is the access to that attribute crosses a FK relation which is not linked by cacheops for invalidation. This is very similar to the root cause described in #3304 and the fix is equally similar. This highlights again that we need to make sure we are using `prefetch_related()` for all FK relationships to ensure invalidation linking for `SET_NULL` conditions.
adam added the type: bugstatus: accepted labels 2025-12-29 18:30:38 +01:00
adam closed this issue 2025-12-29 18:30:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3691