opendcim / openDCIM

An open source (GPL v3) Data Center Inventory Management (DCIM) application.
http://opendcim.org
305 stars 204 forks source link

Adding power connections to a device causes a 500 server error #1555

Open abeeson opened 2 weeks ago

abeeson commented 2 weeks ago

Describe the bug Attempting to increase the power connections on a device by incrementing the value, either by manually typing then pressing update, or by hitting the arrow and having it dynamically load immediately results in a 500 error.

Looking in the PHP error log from our instance this is reported: [27-Aug-2024 16:34:48 Australia/Sydney] PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '401-1' for key 'PRIMARY' in /var/www/html/dciminf/classes/PowerPorts.class.php:106 Stack trace:

0 /var/www/html/dciminf/classes/PowerPorts.class.php(106): PDO->query()

1 /var/www/html/dciminf/classes/PowerPorts.class.php(152): PowerPorts->createPort()

2 /var/www/html/dciminf/classes/Device.class.php(899): PowerPorts::createPorts()

3 /var/www/html/dciminf/devices.php(723): Device->UpdateDevice()

4 {main}

thrown in /var/www/html/dciminf/classes/PowerPorts.class.php on line 106

(The above PHP error was for device ID 401, adding power connection 2)

This is likely related to this issue: https://github.com/opendcim/openDCIM/issues/1552 as the descriptions are similar.

To Reproduce Steps to reproduce the behavior:

  1. Go to a network device in a rack (https://demo.opendcim.org/devices.php?DeviceID=1)
  2. Click on the power connections field
  3. Press the up arrow to change it from 2 to 3
  4. See error 500 page that loads

Note: the value will increment and save, to return it back you need to reload the device, drop the value back down and then save the update.

To work around this to add/restore connections, you can delete all the power connections by setting it to 0 and pressing delete on them, then edit the value to the desired number by typing it and pressing save. This only works on initial creation of power connections, so fixing it requires blowing them all away and recreating.

Were you able to reproduce this on the dev or demo sites? Yes, see demo device linked in reproduction steps

Expected behavior Power connection adds like data ports does.

Screenshots N/A, 500 error is essentially blank so nothing to show

Desktop (please complete the following information):