Internal server error on PATCH request to device bay #2949

Closed
opened 2025-12-29 18:23:52 +01:00 by adam · 3 comments
Owner

Originally created by @ajknv on GitHub (Oct 11, 2019).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.3

Steps to Reproduce

  1. Make a PATCH request API endpoint "dcim/device-bays" to install a child device.
  2. Make another PATCH request to "dcim/device-bays" with a different device-bay ID but the same "installed_device" id for the child device.

Expected Behavior

Installing the same child device twice into separate device bays can be reasonably viewed as an error, but the error should be a graceful application error of some kind rather than an internal server error. (Alternately/debatably the request could be treated as a movement of the child device from one bay to another.)

Observed Behavior

An internal server error tracing a duplicate key violation exception:

Exception: HTTP error 500 (Internal Server Error) - 
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Server Error</title>
    <link rel="stylesheet" href="/static/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css">
    <meta charset="UTF-8">
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <div class="panel panel-danger" style="margin-top: 200px">
                    <div class="panel-heading">
                        <strong>
                            <i class="fa fa-warning"></i>
                            Server Error
                        </strong>
                    </div>
                    <div class="panel-body">
                        
                            <p>
                                There was a problem with your request. Please contact an administrator.
                            </p>
                        
                        <hr />
                        <p>
                            The complete exception is provided below:
                        </p>
<pre><strong><class &#39;django.db.utils.IntegrityError&#39;></strong><br />
duplicate key value violates unique constraint &quot;dcim_devicebay_installed_device_id_key&quot;
DETAIL:  Key (installed_device_id)=(3205) already exists.
</pre>
                        <p>
                            If further assistance is required, please post to the <a href="https://groups.google.com/forum/#!forum/netbox-discuss">NetBox mailing list</a>.
                        </p>
                        <div class="text-right">
                            <a href="/" class="btn btn-primary">Home Page</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
Originally created by @ajknv on GitHub (Oct 11, 2019). ### Environment * Python version: 3.6.8 * NetBox version: 2.6.3 ### Steps to Reproduce 1. Make a PATCH request API endpoint "dcim/device-bays" to install a child device. 2. Make another PATCH request to "dcim/device-bays" with a different device-bay ID but the same "installed_device" id for the child device. ### Expected Behavior Installing the same child device twice into separate device bays can be reasonably viewed as an error, but the error should be a graceful application error of some kind rather than an internal server error. (Alternately/debatably the request could be treated as a movement of the child device from one bay to another.) ### Observed Behavior An internal server error tracing a duplicate key violation exception: ``` Exception: HTTP error 500 (Internal Server Error) - <!DOCTYPE html> <html lang="en"> <head> <title>Server Error</title> <link rel="stylesheet" href="/static/bootstrap-3.4.1-dist/css/bootstrap.min.css"> <link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css"> <meta charset="UTF-8"> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-6 col-md-offset-3"> <div class="panel panel-danger" style="margin-top: 200px"> <div class="panel-heading"> <strong> <i class="fa fa-warning"></i> Server Error </strong> </div> <div class="panel-body"> <p> There was a problem with your request. Please contact an administrator. </p> <hr /> <p> The complete exception is provided below: </p> <pre><strong><class &#39;django.db.utils.IntegrityError&#39;></strong><br /> duplicate key value violates unique constraint &quot;dcim_devicebay_installed_device_id_key&quot; DETAIL: Key (installed_device_id)=(3205) already exists. </pre> <p> If further assistance is required, please post to the <a href="https://groups.google.com/forum/#!forum/netbox-discuss">NetBox mailing list</a>. </p> <div class="text-right"> <a href="/" class="btn btn-primary">Home Page</a> </div> </div> </div> </div> </div> </div> </body> </html> ```
adam added the type: bugstatus: accepted labels 2025-12-29 18:23:52 +01:00
adam closed this issue 2025-12-29 18:23:53 +01:00
Author
Owner

@DanSheps commented on GitHub (Oct 17, 2019):

Hello,

I am unable to reproduce this on https://master.netbox.dansheps.com/:

  • Create Device PD1
  • Create Device CD1
  • Perform the below API operations:
curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/device-bays/1/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"installed_device\": 84}"
curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/devices/84/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"comments\": \"Test\"}"
curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/device-bays/1/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"installed_device\": 84}"

This does not present any error. Could you please provide reproducible steps?

@DanSheps commented on GitHub (Oct 17, 2019): Hello, I am unable to reproduce this on https://master.netbox.dansheps.com/: * Create Device PD1 * Create Device CD1 * Perform the below API operations: ``` curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/device-bays/1/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"installed_device\": 84}" curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/devices/84/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"comments\": \"Test\"}" curl -X PATCH "https://master.netbox.dansheps.com/api/dcim/device-bays/1/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"installed_device\": 84}" ``` This does not present any error. Could you please provide reproducible steps?
Author
Owner

@ajknv commented on GitHub (Oct 18, 2019):

Revised the issue description. Turns out the failure was triggered by trying to install the same child device into two different device bays. More of a logical error now, of course, but it could still be handled more gracefully.

@ajknv commented on GitHub (Oct 18, 2019): Revised the issue description. Turns out the failure was triggered by trying to install the same child device into two different device bays. More of a logical error now, of course, but it could still be handled more gracefully.
Author
Owner

@DanSheps commented on GitHub (Oct 18, 2019):

Thanks for confirming ajknv, I do agree that it should be a proper API error message, instead of what you are receiving.

@DanSheps commented on GitHub (Oct 18, 2019): Thanks for confirming ajknv, I do agree that it should be a proper API error message, instead of what you are receiving.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2949