Create of VLAN using the API and /available-vlans/ fails when role or tenant is present #8454

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

Originally created by @einaram on GitHub (Aug 10, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.6-beta1

Python version

3.10

Steps to Reproduce

  1. Create a tenant and note the ID
  2. Create a VLAN group and note the ID
  3. Run a POST to `api/ipam/vlan-groups//available-vlans/ like:

curl -X 'POST' \
  'https://demo.netbox.dev/api/ipam/vlan-groups/2/available-vlans/' \
  -d '{
  "name": "a_VLAN_name",
  "tenant": 2
}'

Expected Behavior

A new VLAN should be created

Observed Behavior

Bad request is returned with an error message that indicates that the deserialization used the tenant object instead of the ID:

  "tenant": [
    "Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value: Strickland Propane"
  ]
}
Originally created by @einaram on GitHub (Aug 10, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.6-beta1 ### Python version 3.10 ### Steps to Reproduce 1. Create a tenant and note the ID 2. Create a VLAN group and note the ID 3. Run a POST to `api/ipam/vlan-groups/<VLAN-group-id>/available-vlans/ like: ``` curl -X 'POST' \ 'https://demo.netbox.dev/api/ipam/vlan-groups/2/available-vlans/' \ -d '{ "name": "a_VLAN_name", "tenant": 2 }' ``` ### Expected Behavior A new VLAN should be created ### Observed Behavior Bad request is returned with an error message that indicates that the deserialization used the tenant object instead of the ID: ```{ "tenant": [ "Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value: Strickland Propane" ] } ```
adam added the type: bugstatus: under reviewseverity: medium labels 2025-12-29 20:36:56 +01:00
adam closed this issue 2025-12-29 20:36:56 +01:00
Author
Owner

@einaram commented on GitHub (Aug 10, 2023):

I have tested possible solution by not deserializing requested_vlans and instead adding vid to the raw data. This, and tests modified to test this behavoir is available here:
https://github.com/netbox-community/netbox/compare/develop...einaram:netbox:13440-fix-available-vlan-post

@einaram commented on GitHub (Aug 10, 2023): I have tested possible solution by not deserializing `requested_vlans` and instead adding `vid` to the raw data. This, and tests modified to test this behavoir is available here: https://github.com/netbox-community/netbox/compare/develop...einaram:netbox:13440-fix-available-vlan-post
Author
Owner

@jeremystretch commented on GitHub (Aug 23, 2023):

This and similar API endpoints were refactored recently in feature to use the new common AvailableObjectsView (see #12180), however the bug does still exist. Testing shows that tenant assignment works as expected when provisioning available IPs, but not for available VLANs. This is due to a difference between the serializers: CreateAvailableVLANSerializer defines a tenant field whereas AvailableIPSerializer does not.

Further investigation is needed to determine the appropriate fix. We need to ensure that all serializers that enable the automatic creation of "available" objects operate in a consistent manner.

@jeremystretch commented on GitHub (Aug 23, 2023): This and similar API endpoints were refactored recently in `feature` to use the new common AvailableObjectsView (see #12180), however the bug does still exist. Testing shows that tenant assignment works as expected when provisioning available IPs, but not for available VLANs. This is due to a difference between the serializers: CreateAvailableVLANSerializer defines a `tenant` field whereas AvailableIPSerializer does not. Further investigation is needed to determine the appropriate fix. We need to ensure that _all_ serializers that enable the automatic creation of "available" objects operate in a consistent manner.
Author
Owner

@jeremystretch commented on GitHub (Sep 25, 2023):

@arthanson this may be related to #13746

@jeremystretch commented on GitHub (Sep 25, 2023): @arthanson this may be related to #13746
Author
Owner

@arthanson commented on GitHub (Sep 25, 2023):

This is fixed by #13746

@arthanson commented on GitHub (Sep 25, 2023): This is fixed by #13746
Author
Owner

@jeremystretch commented on GitHub (Oct 5, 2023):

Confirmed that this has been resolved by PR #13889. Thanks @arthanson!

@jeremystretch commented on GitHub (Oct 5, 2023): Confirmed that this has been resolved by PR #13889. Thanks @arthanson!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8454