Skip to content

Commit 4c7c599

Browse files
MichaelUrayCodex
authored andcommitted
[fix] Guard missing skip_push_update_on_save in register view
DeviceRegisterView._update_device_name calls ``device.skip_push_update_on_save()`` whenever an agent re-registers with a hostname different from the MAC address. While the method is defined on AbstractDevice, subclasses or older installations that lack it would crash with AttributeError on every such re-registration (HTTP 500). This breaks the consistent_registration / factory-reset workflow: 1. A router does a factory reset and loses its local UUID/key. 2. The agent computes a consistent key and POSTs to /register/. 3. OpenWISP finds the existing device by key. 4. The view enters _update_device_name (hostname differs from MAC). 5. If skip_push_update_on_save is missing, AttributeError → HTTP 500. 6. The agent sees no X-Openwisp-Controller header and aborts. 7. After 6 retries procd kills the agent. Wrap the call in ``getattr`` so the registration path succeeds whether the helper method exists or not. The guard is forward-compatible. Closes #1331
1 parent 0d17acd commit 4c7c599

File tree

1 file changed

+7
-1
lines changed
  • openwisp_controller/config/controller

1 file changed

+7
-1
lines changed

openwisp_controller/config/controller/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,13 @@ def _update_device_name(self, request, device):
475475
normalized_name = name.replace(":", "").replace("-", "").lower()
476476
if normalized_name != normalized_mac:
477477
device.name = name
478-
device.skip_push_update_on_save()
478+
# NOTE: ``device.skip_push_update_on_save()`` is defined on
479+
# AbstractDevice, but we guard the call defensively so that
480+
# subclasses or older installations that may lack the method
481+
# do not crash during factory-reset re-registration.
482+
skip = getattr(device, "skip_push_update_on_save", None)
483+
if callable(skip):
484+
skip()
479485

480486

481487
class GetVpnView(SingleObjectMixin, View):

0 commit comments

Comments
 (0)