Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT on Existing Devices Returns Errors #1421

Closed
zachmoody opened this issue Aug 11, 2017 · 1 comment
Closed

PUT on Existing Devices Returns Errors #1421

zachmoody opened this issue Aug 11, 2017 · 1 comment
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@zachmoody
Copy link
Contributor

zachmoody commented Aug 11, 2017

Issue type: Bug

Python version: 2.7.6
NetBox version: develop

Updating device with PUT failed RU validation. Seems it was introduced in 1f9806a. I think the error is the result of a ValidationError raised after checking for available RU. Here's the error:

{"non_field_errors":["U<RU> is already occupied or does not have sufficient space to accommodate a(n) <MODEL>."]}

This should test for the behavior.

--- a/netbox/dcim/tests/test_api.py
+++ b/netbox/dcim/tests/test_api.py
@@ -1267,8 +1267,10 @@ class DeviceTest(HttpStatusMixin, APITestCase):
         self.devicerole2 = DeviceRole.objects.create(
             name='Test Device Role 2', slug='test-device-role-2', color='00ff00'
         )
+        self.site1_r1 = Rack.objects.create(name='Test Rack S1R1', site=self.site1)
         self.device1 = Device.objects.create(
-            device_type=self.devicetype1, device_role=self.devicerole1, name='Test Device 1', site=self.site1
+            device_type=self.devicetype1, device_role=self.devicerole1, name='Test Device 1', site=self.site1,
+            rack=self.site1_r1, position=42, face=1
         )
         self.device2 = Device.objects.create(
             device_type=self.devicetype1, device_role=self.devicerole1, name='Test Device 2', site=self.site1
@@ -1331,6 +1333,24 @@ class DeviceTest(HttpStatusMixin, APITestCase):
         self.assertEqual(device1.name, data['name'])
         self.assertEqual(device1.site_id, data['site'])

+    def test_update_device_field(self):
+        '''Update a single field on a device'''
+        data = {
+            'name': 'Test Device X',
+            'device_type': self.devicetype1.pk,
+            'device_role': self.devicerole1.pk,
+            'site': self.site1.pk,
+            'position': 42,
+            'rack': self.site1_r1.pk,
+            'face': 1,
+        }
+        url = reverse('dcim-api:device-detail', kwargs={'pk': self.device1.pk})
+        response = self.client.put(url, data, **self.header)
+        self.assertHttpStatus(response, status.HTTP_200_OK)
+        self.assertEqual(Device.objects.count(), 3)
+        device1 = Device.objects.get(pk=response.data['id'])
+        self.assertEqual(device1.name, 'Test Device X')
+
     def test_delete_device(self):

         url = reverse('dcim-api:device-detail', kwargs={'pk': self.device1.pk})
@jeremystretch jeremystretch added the type: bug A confirmed report of unexpected behavior in the application label Aug 14, 2017
@zachmoody
Copy link
Contributor Author

Dug a bit more into this. Seems that self.pk is None which is causing the logic in clean() to treat it like a new device. 🤔

zachmoody pushed a commit that referenced this issue Aug 15, 2017
lampwins pushed a commit to lampwins/netbox that referenced this issue Oct 13, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants