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

Closed
nemesifier opened this issue May 31, 2024 · 0 comments · Fixed by #886
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
praptisharma28 added a commit that referenced this issue Jul 22, 2024
praptisharma28 added a commit that referenced this issue Jul 22, 2024
praptisharma28 added a commit that referenced this issue Jul 24, 2024
praptisharma28 added a commit that referenced this issue Jul 25, 2024
praptisharma28 added a commit that referenced this issue Sep 9, 2024
praptisharma28 added a commit that referenced this issue Sep 9, 2024
praptisharma28 added a commit that referenced this issue Sep 11, 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.
Development

Successfully merging a pull request may close this issue.

1 participant