Fixes #3269: Raise validation error when specifying non-existent cable terminationss

This commit is contained in:
Jeremy Stretch 2019-06-24 15:42:15 -04:00
parent cf770bf40c
commit 3fdb655a92
2 changed files with 58 additions and 43 deletions

View File

@ -8,6 +8,7 @@ v2.6.1 (FUTURE)
## Bug Fixes
* [#3229](https://github.com/digitalocean/netbox/issues/3229) - Limit rack group selection by parent site on racks list
* [#3269](https://github.com/digitalocean/netbox/issues/3269) - Raise validation error when specifying non-existent cable terminations
* [#3275](https://github.com/digitalocean/netbox/issues/3275) - Fix error when adding power outlets to a device type
* [#3279](https://github.com/digitalocean/netbox/issues/3279) - Reset the PostgreSQL sequence for Tag and TaggedItem IDs
* [#3283](https://github.com/digitalocean/netbox/issues/3283) - Fix rack group assignment on PowerFeed CSV import

View File

@ -2747,7 +2747,21 @@ class Cable(ChangeLoggedModel):
def clean(self):
if self.termination_a and self.termination_b:
# Validate that termination A exists
try:
self.termination_a_type.model_class().objects.get(pk=self.termination_a_id)
except ObjectDoesNotExist:
raise ValidationError({
'termination_a': 'Invalid ID for type {}'.format(self.termination_a_type)
})
# Validate that termination B exists
try:
self.termination_b_type.model_class().objects.get(pk=self.termination_b_id)
except ObjectDoesNotExist:
raise ValidationError({
'termination_b': 'Invalid ID for type {}'.format(self.termination_b_type)
})
type_a = self.termination_a_type.model
type_b = self.termination_b_type.model