Moving primary ip address for a device to a new device generates Integrity error #7740

Closed
opened 2025-12-29 20:27:41 +01:00 by adam · 5 comments
Owner

Originally created by @drossy on GitHub (Mar 8, 2023).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.4.5

Python version

3.8

Steps to Reproduce

We encountered this on our local version (3.4.2) but were able to reproduce on the demo instance (3.4.5)

  1. Browse to the edit page for an ipv4 address marked as primary ip for a device
  2. Change the device and interface to another device and interface, leave the "Make this the primary IP for the device/VM" box ticked
  3. Press Save

Expected Behavior

IP address is updated to be set as primary ip for the new device, and assigned to the new interface, and is no longer primary ip address for the old device and is no longer assigned to the old interface.

Observed Behavior

The web server displays:

<class 'django.db.utils.IntegrityError'>

duplicate key value violates unique constraint "dcim_device_primary_ip4_id_key"
DETAIL: Key (primary_ip4_id)=(185) already exists.

Originally created by @drossy on GitHub (Mar 8, 2023). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.4.5 ### Python version 3.8 ### Steps to Reproduce We encountered this on our local version (3.4.2) but were able to reproduce on the demo instance (3.4.5) 1. Browse to the edit page for an ipv4 address marked as primary ip for a device 2. Change the device and interface to another device and interface, leave the "Make this the primary IP for the device/VM" box ticked 3. Press Save ### Expected Behavior IP address is updated to be set as primary ip for the new device, and assigned to the new interface, and is no longer primary ip address for the old device and is no longer assigned to the old interface. ### Observed Behavior The web server displays: <class 'django.db.utils.IntegrityError'> duplicate key value violates unique constraint "dcim_device_primary_ip4_id_key" DETAIL: Key (primary_ip4_id)=(185) already exists.
adam added the type: bugstatus: accepted labels 2025-12-29 20:27:41 +01:00
adam closed this issue 2025-12-29 20:27:41 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 13, 2023):

IP address is updated to be set as primary ip for the new device, and assigned to the new interface, and is no longer primary ip address for the old device and is no longer assigned to the old interface.

I'm not sure this should be the desired behavior. Primary IPs are explicitly designated, so automatically nullifying their assignments seems dangerous. Rather than handling this automatically, it would be safer to instead raise a validation failure, calling to the user's attention that the IP is assigned as primary for its current parent.

@jeremystretch commented on GitHub (Mar 13, 2023): > IP address is updated to be set as primary ip for the new device, and assigned to the new interface, and is no longer primary ip address for the old device and is no longer assigned to the old interface. I'm not sure this should be the desired behavior. Primary IPs are explicitly designated, so automatically nullifying their assignments seems dangerous. Rather than handling this automatically, it would be safer to instead raise a validation failure, calling to the user's attention that the IP is assigned as primary for its current parent.
Author
Owner

@jeremystretch commented on GitHub (Mar 16, 2023):

Per #11905, this also concerns primary IP assignment for virtual machines.

@jeremystretch commented on GitHub (Mar 16, 2023): Per #11905, this also concerns primary IP assignment for virtual machines.
Author
Owner

@drossy commented on GitHub (Mar 21, 2023):

I'm not sure this should be the desired behavior. Primary IPs are explicitly designated, so automatically nullifying their assignments seems dangerous. Rather than handling this automatically, it would be safer to instead raise a validation failure, calling to the user's attention that the IP is assigned as primary for its current parent.

I wouldn't have a problem with that, we're currently working round this issue by undesignated the ip as primary and then moving the ip.

@drossy commented on GitHub (Mar 21, 2023): > > I'm not sure this should be the desired behavior. Primary IPs are explicitly designated, so automatically nullifying their assignments seems dangerous. Rather than handling this automatically, it would be safer to instead raise a validation failure, calling to the user's attention that the IP is assigned as primary for its current parent. I wouldn't have a problem with that, we're currently working round this issue by undesignated the ip as primary and then moving the ip.
Author
Owner

@salfers commented on GitHub (Mar 24, 2023):

Closely related (I think this is what the reporter in #11905 was trying to say):

  • Have a device or VM with 1.2.3.4 assigned to one of the interfaces, 1.2.3.4 is also set as primary IP for the device
  • Edit the IP 1.2.3.4 and remove the device + interface assignment
  • Open the device page and see that 1.2.3.4 is still shown as primary IP

If you click edit and re-save the device the primary IP will automatically disappear, so this state is not stable.

@salfers commented on GitHub (Mar 24, 2023): Closely related (I think this is what the reporter in #11905 was trying to say): * Have a device or VM with 1.2.3.4 assigned to one of the interfaces, 1.2.3.4 is also set as primary IP for the device * Edit the IP 1.2.3.4 and remove the device + interface assignment * Open the device page and see that 1.2.3.4 is still shown as primary IP If you click edit and re-save the device the primary IP will automatically disappear, so this state is not stable.
Author
Owner

@bitcollector1 commented on GitHub (May 19, 2023):

somewhere along the line it was a (2) step process from GUI to remove a primary IP and I thought it was kind of annoying. After an upgrade (not sure which) this requirement was removed and I was happy until I started running into this Primary IP still assigned even though the IP was removed from the interface itself!

This has been causing quite a few headaches, hopefully it gets fixed before too much longer.

@bitcollector1 commented on GitHub (May 19, 2023): somewhere along the line it was a (2) step process from GUI to remove a primary IP and I thought it was kind of annoying. After an upgrade (not sure which) this requirement was removed and I was happy until I started running into this Primary IP still assigned even though the IP was removed from the interface itself! This has been causing quite a few headaches, hopefully it gets fixed before too much longer.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7740