networktocode/ntc-netbox-plugin-onboarding

Device display error after deleting its primary IP address

matthieup opened this issue · 0 comments

Environment

  • Python version: 3.8.8
  • NetBox version: 2.10.8
  • ntc-netbox-plugin-onboarding version: 2.1.0 ( both pip, and built from master and develop )
    Also this was tested under docker via image netboxcommunity/netbox:v2.10.8-ldap.

Steps to Reproduce

  1. Create device Test_01
  2. Create test-interface and binding to to Test_01
  3. Create IPaddress 1.1.1.1/24 and binding to test-interface
  4. Set primary IP of Test_01 to 1.1.1.1/24
  5. Delete IPaddress 1.1.1.1/24
  6. View Device Test_01 and it'll get an error of IPaddressDoesNotExist

Confirmed also that this only happens when having netbox_onboarding plugin enabled in netbox.
This was also reported on netbox-community/netbox#6069 before we found out this is only happening when netbox_onboarding is enabled.

Expected Behavior

After removing primary IP address of device, the device details should show up correctly without a restart of netbox.

Observed Behavior

Gettting an exception <class 'ipam.models.IPAddress.DoesNotExist'> as can be seen in the attached pictures.

Restarting Netbox fixes the problem, so it seems it may be related to a cache issue

Tested fix

As a quick fix, I tried to catch the exception by:

        try:
            ip = self.device.primary_ip4
        except IPAddress.DoesNotExist:
            return "unknown"

in functions last_check_attempt_date(self), last_check_successful_date(self), status(self) and last_ot(self) and device was able to be displayed correctly.

snapshot-ipv4-1
snapshot-ipv4-2