Skip to content

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

@FragmentedPacket

Description

@FragmentedPacket

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
    }

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions