Skip to content

Commit

Permalink
Fixes netbox-community#1275: Raise validation error on prefix import …
Browse files Browse the repository at this point in the history
…when multiple VLANs are found
  • Loading branch information
jeremystretch committed Jun 15, 2017
1 parent 9847303 commit 146435c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netbox/ipam/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

from django import forms
from django.core.exceptions import MultipleObjectsReturned
from django.db.models import Count

from dcim.models import Site, Rack, Device, Interface
Expand Down Expand Up @@ -301,6 +302,10 @@ def clean(self):
))
else:
raise forms.ValidationError("Global VLAN {} not found in group {}".format(vlan_vid, vlan_group))
except MultipleObjectsReturned:
raise forms.ValidationError(
"Multiple VLANs with VID {} found in group {}".format(vlan_vid, vlan_group)
)
elif vlan_vid:
try:
self.instance.vlan = VLAN.objects.get(site=site, group__isnull=True, vid=vlan_vid)
Expand All @@ -309,6 +314,8 @@ def clean(self):
raise forms.ValidationError("VLAN {} not found in site {}".format(vlan_vid, site))
else:
raise forms.ValidationError("Global VLAN {} not found".format(vlan_vid))
except MultipleObjectsReturned:
raise forms.ValidationError("Multiple VLANs with VID {} found".format(vlan_vid))


class PrefixBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
Expand Down

0 comments on commit 146435c

Please sign in to comment.