diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index cb5a40c88..ac1affdef 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -1462,7 +1462,7 @@ class Interface(models.Model): self.untagged_vlan = None # Only "tagged" interfaces may have tagged VLANs assigned. ("tagged all" implies all VLANs are assigned.) - if self.mode is not IFACE_MODE_TAGGED: + if self.pk and self.mode is not IFACE_MODE_TAGGED: self.tagged_vlans.clear() return super(Interface, self).save(*args, **kwargs) diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index ef17a8786..37743b499 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -5,7 +5,9 @@ from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase -from dcim.constants import IFACE_FF_1GE_FIXED, IFACE_FF_LAG, SUBDEVICE_ROLE_CHILD, SUBDEVICE_ROLE_PARENT +from dcim.constants import ( + IFACE_FF_1GE_FIXED, IFACE_FF_LAG, IFACE_MODE_TAGGED, SUBDEVICE_ROLE_CHILD, SUBDEVICE_ROLE_PARENT, +) from dcim.models import ( ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, @@ -2319,6 +2321,7 @@ class InterfaceTest(HttpStatusMixin, APITestCase): data = { 'device': self.device.pk, 'name': 'Test Interface 4', + 'mode': IFACE_MODE_TAGGED, 'tagged_vlans': [self.vlan1.id, self.vlan2.id], 'untagged_vlan': self.vlan3.id } @@ -2366,18 +2369,21 @@ class InterfaceTest(HttpStatusMixin, APITestCase): { 'device': self.device.pk, 'name': 'Test Interface 4', + 'mode': IFACE_MODE_TAGGED, 'tagged_vlans': [self.vlan1.id], 'untagged_vlan': self.vlan2.id, }, { 'device': self.device.pk, 'name': 'Test Interface 5', + 'mode': IFACE_MODE_TAGGED, 'tagged_vlans': [self.vlan1.id], 'untagged_vlan': self.vlan2.id, }, { 'device': self.device.pk, 'name': 'Test Interface 6', + 'mode': IFACE_MODE_TAGGED, 'tagged_vlans': [self.vlan1.id], 'untagged_vlan': self.vlan2.id, },