Kaynağa Gözat

Fixes #3130: Fix exception when creating a new power outlet

Jeremy Stretch 6 yıl önce
ebeveyn
işleme
d4d355dce6
2 değiştirilmiş dosya ile 5 ekleme ve 3 silme
  1. 1 0
      CHANGELOG.md
  2. 4 3
      netbox/dcim/forms.py

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ v2.6.0 (FUTURE)
 * [#3123](https://github.com/digitalocean/netbox/issues/3123) - Exempt `/metrics` view from authentication
 * [#3125](https://github.com/digitalocean/netbox/issues/3125) - Fix exception when viewing PDUs
 * [#3126](https://github.com/digitalocean/netbox/issues/3126) - Incorrect calculation of PowerFeed available power
+* [#3130](https://github.com/digitalocean/netbox/issues/3130) - Fix exception when creating a new power outlet
 
 
 ---

+ 4 - 3
netbox/dcim/forms.py

@@ -2006,9 +2006,10 @@ class PowerOutletForm(BootstrapMixin, forms.ModelForm):
         super().__init__(*args, **kwargs)
 
         # Limit power_port choices to the local device
-        self.fields['power_port'].queryset = PowerPort.objects.filter(
-            device=self.instance.device
-        )
+        if hasattr(self.instance, 'device'):
+            self.fields['power_port'].queryset = PowerPort.objects.filter(
+                device=self.instance.device
+            )
 
 
 class PowerOutletCreateForm(ComponentForm):