VLAN Group scope_type virtualization received invalid content type via API POST #4890

Closed
opened 2025-12-29 19:21:41 +01:00 by adam · 0 comments
Owner

Originally created by @FragmentedPacket on GitHub (May 9, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v2.11.3

Python version

3.8

Steps to Reproduce

  1. Attempt to POST to /api/ipam/vlan-groups with scope_type set to virtualization.cluster or virtualization.clustergroup

It appears the API serializer doesn't follow what the model has specified.

https://github.com/netbox-community/netbox/blob/develop/netbox/ipam/api/serializers.py#L117

I believe this should be pretty simple to resolve by either not overriding the search for it in the serializer and letting DRF take control or making the following change.

from ipam.constants import IPADDRESS_ASSIGNMENT_MODELS, VLANGROUP_SCOPE_TYPES

    scope_type = ContentTypeField(
        queryset=ContentType.objects.filter(
            model__in=VLANGROUP_SCOPE_TYPES
        ),
        required=False
    )

Expected Behavior

A new VLAN Group scoped to a virtualization endpoint.

Observed Behavior

{
  "scope_type": [
    "Invalid content type: virtualization.cluster"
  ]
}

Works via UI and pulling from API.

    {
      "id": 1,
      "url": "http://myohman.local:9000/api/ipam/vlan-groups/1/",
      "display": "Test Vlan Group",
      "name": "Test Vlan Group",
      "slug": "test-vlan-group",
      "scope_type": "virtualization.clustergroup",
      "scope_id": 1,
      "scope": {
        "id": 1,
        "url": "http://myohman.local:9000/api/virtualization/cluster-groups/1/",
        "display": "Test Cluster Group",
        "name": "Test Cluster Group",
        "slug": "test-cluster-group"
      },
      "description": "",
      "custom_fields": {},
      "created": "2021-05-08",
      "last_updated": "2021-05-08T19:00:15.716607Z",
      "vlan_count": 1
    }
Originally created by @FragmentedPacket on GitHub (May 9, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v2.11.3 ### Python version 3.8 ### Steps to Reproduce 1. Attempt to POST to `/api/ipam/vlan-groups` with `scope_type` set to `virtualization.cluster` or `virtualization.clustergroup` It appears the API serializer doesn't follow what the model has specified. https://github.com/netbox-community/netbox/blob/develop/netbox/ipam/api/serializers.py#L117 I believe this should be pretty simple to resolve by either not overriding the search for it in the serializer and letting DRF take control or making the following change. ```python from ipam.constants import IPADDRESS_ASSIGNMENT_MODELS, VLANGROUP_SCOPE_TYPES scope_type = ContentTypeField( queryset=ContentType.objects.filter( model__in=VLANGROUP_SCOPE_TYPES ), required=False ) ``` ### Expected Behavior A new VLAN Group scoped to a virtualization endpoint. ### Observed Behavior ```json { "scope_type": [ "Invalid content type: virtualization.cluster" ] } ``` Works via UI and pulling from API. ```json { "id": 1, "url": "http://myohman.local:9000/api/ipam/vlan-groups/1/", "display": "Test Vlan Group", "name": "Test Vlan Group", "slug": "test-vlan-group", "scope_type": "virtualization.clustergroup", "scope_id": 1, "scope": { "id": 1, "url": "http://myohman.local:9000/api/virtualization/cluster-groups/1/", "display": "Test Cluster Group", "name": "Test Cluster Group", "slug": "test-cluster-group" }, "description": "", "custom_fields": {}, "created": "2021-05-08", "last_updated": "2021-05-08T19:00:15.716607Z", "vlan_count": 1 } ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:21:41 +01:00
adam closed this issue 2025-12-29 19:21:42 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4890