From e5b0ab4dca19a8affab5333fb3391ee092f433ef Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 22:27:40 -0400 Subject: [PATCH] Fixes #26: Corrected rack validation to work when there are no devices within the rack --- netbox/dcim/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 5ff233c9c..0c587dd3d 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -188,10 +188,11 @@ class Rack(CreatedUpdatedModel): # Validate that Rack is tall enough to house the installed Devices if self.pk: top_device = Device.objects.filter(rack=self).order_by('-position').first() - min_height = top_device.position + top_device.device_type.u_height - 1 - if self.u_height < min_height: - raise ValidationError("Rack must be at least {}U tall with currently installed devices." - .format(min_height)) + if top_device: + min_height = top_device.position + top_device.device_type.u_height - 1 + if self.u_height < min_height: + raise ValidationError("Rack must be at least {}U tall with currently installed devices." + .format(min_height)) def to_csv(self): return ','.join([