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

[bug] Subnet division rule validation fails with uncaught exception if subnet is left empty #866

Open
nemesifier opened this issue May 31, 2024 · 0 comments
Labels
bug Good first issue Easy issue that new contributors may like to pick up to get themselves familiar with the repository.

Comments

@nemesifier
Copy link
Member

Try creating a subnet and a subnet division rule in /admin/openwisp_ipam/subnet/add/.
Leave the mandatory "subnet" field empty but try creating the subnet division rule anyway.

Expected result: a validation error is shown in the UI.

Actual result: 500 internal server error.

Stacktrace:

AttributeError: 'NoneType' object has no attribute 'subnets'
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/contrib/admin/options.py", line 688, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
  File "django/contrib/admin/sites.py", line 242, in inner
    return view(request, *args, **kwargs)
  File "reversion/admin.py", line 158, in add_view
    return super().add_view(request, form_url, extra_context)
  File "django/contrib/admin/options.py", line 1886, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "django/contrib/admin/options.py", line 1747, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "django/contrib/admin/options.py", line 1797, in _changeform_view
    if all_valid(formsets) and form_validated:
  File "__init__.py", line 89, in wrapper
    return func(original_callable, *args, **kwargs)
  File "__init__.py", line 155, in all_valid
    if not original_all_valid(formsets):
  File "django/forms/formsets.py", line 579, in all_valid
    return all([formset.is_valid() for formset in formsets])
  File "django/forms/formsets.py", line 579, in <listcomp>
    return all([formset.is_valid() for formset in formsets])
  File "django/forms/formsets.py", line 384, in is_valid
    self.errors
  File "django/forms/formsets.py", line 366, in errors
    self.full_clean()
  File "django/forms/formsets.py", line 429, in full_clean
    form_errors = form.errors
  File "django/forms/forms.py", line 196, in errors
    self.full_clean()
  File "django/forms/forms.py", line 435, in full_clean
    self._post_clean()
  File "django/forms/models.py", line 486, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "django/db/models/base.py", line 1477, in full_clean
    self.clean()
  File "openwisp_controller/subnet_division/base/models.py", line 74, in clean
    self._validate_master_subnet_consistency()
  File "openwisp_controller/subnet_division/base/models.py", line 109, in _validate_master_subnet_consistency
    next(master_subnet.subnets(new_prefix=self.size))
@nemesifier nemesifier added bug Good first issue Easy issue that new contributors may like to pick up to get themselves familiar with the repository. labels May 31, 2024
@nemesifier nemesifier added this to To do (general) in OpenWISP Contributor's Board via automation May 31, 2024
@nemesifier nemesifier added this to Backlog in OpenWISP Priorities for next releases via automation May 31, 2024
@nemesifier nemesifier moved this from Backlog to To do in OpenWISP Priorities for next releases May 31, 2024
@nemesifier nemesifier moved this from To do (general) to To do (Python & Django) in OpenWISP Contributor's Board May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Good first issue Easy issue that new contributors may like to pick up to get themselves familiar with the repository.
Projects
OpenWISP Contributor's Board
  
To do (Python & Django)
Development

No branches or pull requests

1 participant