openwisp / openwisp-firmware-upgrader

Firmware upgrade solution for OpenWRT with possibility to add support for other embedded OSes. Provides features like automatic retry for network failures, mass upgrades, REST API and more.
https://openwisp.io/docs/dev/firmware-upgrader/
Other
53 stars 60 forks source link

[bug] Deleting DeviceConnection object for a device with DeviceFirmareImage raises HTTP 500 error #250

Open pandafy opened 7 months ago

pandafy commented 7 months ago

Steps to replicate

  1. Ensure that you have a celery worker running in the background
  2. Create a device
  3. Add a credential to this device from the "Credentials" tab and save the form.
  4. Add a firmware to this device from the "Firmware" tab and save the form. This step will create an UpgradeOperation for this device. Verify this from the "Upgrade Operations" tab.
  5. Delete the credentials from the "Credentials" tab and save the form.
  6. Try saving the form again

Actual Outcome

The application returns HTTP 500 response because of this error

Traceback (most recent call last):
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/contrib/admin/options.py", line 688, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 242, in inner
    return view(request, *args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/openwisp_controller/config/admin.py", line 138, in change_view
    return super().change_view(request, object_id, form_url, extra_context)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/reversion/admin.py", line 162, in change_view
    return super().change_view(request, object_id, form_url, extra_context)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/openwisp_utils/admin.py", line 133, in change_view
    return super().change_view(
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1889, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1747, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1797, in _changeform_view
    if all_valid(formsets) and form_validated:
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/formsets.py", line 579, in all_valid
    return all([formset.is_valid() for formset in formsets])
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/formsets.py", line 579, in <listcomp>
    return all([formset.is_valid() for formset in formsets])
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/formsets.py", line 384, in is_valid
    self.errors
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/formsets.py", line 366, in errors
    self.full_clean()
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/formsets.py", line 429, in full_clean
    form_errors = form.errors
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/forms.py", line 196, in errors
    self.full_clean()
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/forms.py", line 435, in full_clean
    self._post_clean()
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/forms/models.py", line 486, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/home/pandafy/openwisp/venv-firmware/lib/python3.8/site-packages/django/db/models/base.py", line 1477, in full_clean
    self.clean()
  File "/home/pandafy/openwisp/openwisp-firmware-upgrader/openwisp_firmware_upgrader/base/models.py", line 69, in clean
    self.validate_upgrade_options()
  File "/home/pandafy/openwisp/openwisp-firmware-upgrader/openwisp_firmware_upgrader/base/models.py", line 56, in validate_upgrade_options
    if not getattr(self.upgrader_class, 'SCHEMA'):

Exception Type: AttributeError at /admin/config/device/e879d06b-672f-44c9-aa5e-561c56492663/change/
Exception Value: 'NoneType' object has no attribute 'SCHEMA'
pandafy commented 7 months ago

This is partially related to https://github.com/openwisp/openwisp-firmware-upgrader/issues/249