Exception when creating a new interface via API with VLANs assigned #1584

Closed
opened 2025-12-29 16:33:11 +01:00 by adam · 2 comments
Owner

Originally created by @jeremystretch on GitHub (Feb 27, 2018).

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.3.0

Description

Attempting to create a new interface via the API with one or more assigned tagged or untagged VLANs raises a ValueError:

ValueError: "<Interface: eth0>" needs to have a value for field "id" before this many-to-many relationship can be used.

For example:

curl -X POST \
-H "Authorization: Token <TOKEN>" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://localhost:8000/api/dcim/interfaces/ \
--data '{
  "enabled": true,
  "device": 123,
  "name": "eth0",
  "mgmt_only": true,
  "untagged_vlan": null,
  "mac_address": null,
  "form_factor": "1000",
  "mode": null,
  "description": "testing",
  "tagged_vlans": [456],
  "lag": null
}'

This also occurs when an empty list of VLAN PKs is provided. It does not occur when the tagged_vlans and untagged_vlans fields are not present.

Originally created by @jeremystretch on GitHub (Feb 27, 2018). ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [x] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.3.0 ### Description Attempting to create a new interface via the API with one or more assigned tagged or untagged VLANs raises a ValueError: ``` ValueError: "<Interface: eth0>" needs to have a value for field "id" before this many-to-many relationship can be used. ``` For example: ``` curl -X POST \ -H "Authorization: Token <TOKEN>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://localhost:8000/api/dcim/interfaces/ \ --data '{ "enabled": true, "device": 123, "name": "eth0", "mgmt_only": true, "untagged_vlan": null, "mac_address": null, "form_factor": "1000", "mode": null, "description": "testing", "tagged_vlans": [456], "lag": null }' ``` This also occurs when an empty list of VLAN PKs is provided. It does not occur when the `tagged_vlans` and `untagged_vlans` fields are not present.
adam added the type: bugstatus: accepted labels 2025-12-29 16:33:11 +01:00
adam closed this issue 2025-12-29 16:33:11 +01:00
Author
Owner

@lampwins commented on GitHub (Feb 27, 2018):

Whoops. Stupid M2M relations... Looking back at the testing I did, it was only on existing interfaces. Should be easy enough to fix in the view. Would you like me to take care of this @jeremystretch ?

@lampwins commented on GitHub (Feb 27, 2018): Whoops. Stupid M2M relations... Looking back at the testing I did, it was only on existing interfaces. Should be easy enough to fix in the view. Would you like me to take care of this @jeremystretch ?
Author
Owner

@jeremystretch commented on GitHub (Feb 27, 2018):

@lampwins Go for it

@jeremystretch commented on GitHub (Feb 27, 2018): @lampwins Go for it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1584