API allows interface creation without 'type' specified #3405

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

Originally created by @falz on GitHub (Feb 25, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.8
  • NetBox version: 2.7.4

Steps to Reproduce

  1. Write code to create an interface via netbox API.
  2. When creating it, set type to null.
  3. I'm testing with this other author's code: https://github.com/VictorPavlushin/netbox-netdev-inventory/ and working on bugfixes. I would expect running this code to easily recreate behavior.
  4. the bug of setting null is the fault of the above code, but netbox itsself still creates an interface without Type set

Expected Behavior

No interface created due to invalid api POST

Observed Behavior

Netbox does output error, but interface is created with blank/null Type.

Data

Host: 127.0.0.1:8001
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 42
Content-Type: application/json
Authorization: Token <REDACTED>

{"device": 37, "name": "GigabitEthernet0"}

HTTP/1.1 201 Created
Server: gunicorn/19.9.0
Date: Thu, 13 Feb 2020 14:39:51 GMT
Connection: close
Content-Type: application/json
Vary: Accept, Cookie, Origin
Allow: GET, POST, HEAD, OPTIONS, TRACE
API-Version: 2.7
X-Frame-Options: SAMEORIGIN
Content-Length: 442

{"id":1168,"device":{"id":37,"url":"http://127.0.0.1:8001/api/dcim/devices/37/","name":"r-ciscodevice","display_name":"r-ciscodevice"},"name":"GigabitEthernet0","type":null,"enabled":true,"lag":null,"mtu":null,"mac_address":null,"mgmt_only":false,"description":"","connected_endpoint_type":null,"connected_endpoint":null,"connection_status":null,"cable":null,"mode":null,"untagged_vlan":null,"tagged_vlans":[],"tags":[],"count_ipaddresses":0}





PUT /api/dcim/interfaces/1168/ HTTP/1.1
Host: 127.0.0.1:8001
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 383
Content-Type: application/json
Authorization: Token <REDACTED>

{"id": 1168, "name": "GigabitEthernet0", "type": null, "enabled": false, "lag": null, "mtu": null, "mac_address": "88:1D:FC:C0:F3:38", "mgmt_only": false, "description": "", "connected_endpoint_type": null, "connected_endpoint": null, "connection_status": null, "cable": null, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0, "device": 37}HTTP/1.1 400 Bad Request
Server: gunicorn/19.9.0
Date: Thu, 13 Feb 2020 14:39:56 GMT
Connection: close
Content-Type: application/json
Vary: Accept, Cookie, Origin
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE
API-Version: 2.7
X-Frame-Options: SAMEORIGIN
Content-Length: 40

{"type":["This field may not be null."]}

Screenshot of interface in gui
device-interface-netbox-2 7 4

Originally created by @falz on GitHub (Feb 25, 2020). Originally assigned to: @jeremystretch 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. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.7.4 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). 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 wrapper like pynetbox. --> ### Steps to Reproduce 1. Write code to create an interface via netbox API. 2. When creating it, set `type` to `null`. 3. I'm testing with this other author's code: https://github.com/VictorPavlushin/netbox-netdev-inventory/ and working on bugfixes. I would expect running this code to easily recreate behavior. 4. the bug of setting null is the fault of the above code, but netbox itsself still creates an interface without `Type` set <!-- What did you expect to happen? --> ### Expected Behavior No interface created due to invalid api POST <!-- What happened instead? --> ### Observed Behavior Netbox does output error, but interface is created with blank/null Type. ### Data ```POST /api/dcim/interfaces/ HTTP/1.1 Host: 127.0.0.1:8001 User-Agent: python-requests/2.22.0 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 42 Content-Type: application/json Authorization: Token <REDACTED> {"device": 37, "name": "GigabitEthernet0"} HTTP/1.1 201 Created Server: gunicorn/19.9.0 Date: Thu, 13 Feb 2020 14:39:51 GMT Connection: close Content-Type: application/json Vary: Accept, Cookie, Origin Allow: GET, POST, HEAD, OPTIONS, TRACE API-Version: 2.7 X-Frame-Options: SAMEORIGIN Content-Length: 442 {"id":1168,"device":{"id":37,"url":"http://127.0.0.1:8001/api/dcim/devices/37/","name":"r-ciscodevice","display_name":"r-ciscodevice"},"name":"GigabitEthernet0","type":null,"enabled":true,"lag":null,"mtu":null,"mac_address":null,"mgmt_only":false,"description":"","connected_endpoint_type":null,"connected_endpoint":null,"connection_status":null,"cable":null,"mode":null,"untagged_vlan":null,"tagged_vlans":[],"tags":[],"count_ipaddresses":0} PUT /api/dcim/interfaces/1168/ HTTP/1.1 Host: 127.0.0.1:8001 User-Agent: python-requests/2.22.0 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 383 Content-Type: application/json Authorization: Token <REDACTED> {"id": 1168, "name": "GigabitEthernet0", "type": null, "enabled": false, "lag": null, "mtu": null, "mac_address": "88:1D:FC:C0:F3:38", "mgmt_only": false, "description": "", "connected_endpoint_type": null, "connected_endpoint": null, "connection_status": null, "cable": null, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0, "device": 37}HTTP/1.1 400 Bad Request Server: gunicorn/19.9.0 Date: Thu, 13 Feb 2020 14:39:56 GMT Connection: close Content-Type: application/json Vary: Accept, Cookie, Origin Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE API-Version: 2.7 X-Frame-Options: SAMEORIGIN Content-Length: 40 {"type":["This field may not be null."]} ``` Screenshot of interface in gui ![device-interface-netbox-2 7 4](https://user-images.githubusercontent.com/707319/75264270-cc355b00-57b4-11ea-998d-bb9c14a39588.png)
adam added the type: bugstatus: accepted labels 2025-12-29 18:28:47 +01:00
adam closed this issue 2025-12-29 18:28:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3405