From 7467347af146970a2e955a6ebb08f313fdd25ee6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 23 Oct 2019 09:28:00 -0400 Subject: [PATCH] Fixes #3596: Prevent server error when reassigning a device to a new device bay --- docs/release-notes/version-2.6.md | 4 +++- netbox/dcim/models.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 246cc0d91..9321477b7 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -2,12 +2,14 @@ ## Enhancements -* [#3340](https://github.com/netbox-community/netbox/issues/3340) - Add missing options to connect front ports to console ports * [#3445](https://github.com/netbox-community/netbox/issues/3445) - Add support for additional user defined headers to be added to webhook requests * [#3499](https://github.com/netbox-community/netbox/issues/3499) - Add `ca_file_path` to Webhook model to support user supplied CA certificate verification of webhook requests ## Bug Fixes +* [#3340](https://github.com/netbox-community/netbox/issues/3340) - Add missing options to connect front ports to console ports +* [#3596](https://github.com/netbox-community/netbox/issues/3596) - Prevent server error when reassigning a device to a new device bay + --- # v2.6.6 (2019-10-10) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 03f560a59..f86a9c82d 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -2588,6 +2588,16 @@ class DeviceBay(ComponentModel): if self.device == self.installed_device: raise ValidationError("Cannot install a device into itself.") + # Check that the installed device is not already installed elsewhere + if self.installed_device: + current_bay = DeviceBay.objects.filter(installed_device=self.installed_device).first() + if current_bay: + raise ValidationError({ + 'installed_device': "Cannot install the specified device; device is already installed in {}".format( + current_bay + ) + }) + # # Inventory items