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] Creating a quarantine rule for a vlan that already has a quarantine rule causes 500 error #3244

Open
stveit opened this issue Nov 25, 2024 · 0 comments
Labels

Comments

@stveit
Copy link
Contributor

stveit commented Nov 25, 2024

Describe the bug

If you create a quarantine rule in Arnold (/arnold/addquarantinevlan/) for a vlan that already has a quarantine rule, you get a 500 error (See traceback for details)

To Reproduce

Steps to reproduce the behavior: (replace X with any number you want to use, e.g. 100)

  1. Go to/arnold/addquarantinevlan/
  2. Enter vlan X into the vlan input box on the right
  3. Click Add vlan
  4. Enter vlan X into the vlan input box on the right
  5. Click Add vlan
  6. See error

Expected behavior

Since the same Vlan cannot be quarantined twice, I would expect a non-500 error saying that plainly beneath the form or something.

Screenshots

Tracebacks

Traceback (most recent call last):
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

The above exception (duplicate key value violates unique constraint "quarantine_vlan_unique"
DETAIL:  Key (vlan)=(1) already exists.
) was the direct cause of the following exception:
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/source/python/nav/web/arnold/views.py", line 462, in render_quarantine_vlans
    process_quarantinevlan_form(form)
  File "/source/python/nav/web/arnold/views.py", line 502, in process_quarantinevlan_form
    qvlan.save()
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/base.py", line 776, in save_base
    updated = self._save_table(
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/base.py", line 881, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/base.py", line 919, in _do_insert
    return manager._insert(
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
    cursor.execute(sql, params)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/venvs/nav/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /arnold/addquarantinevlan/
Exception Value: duplicate key value violates unique constraint "quarantine_vlan_unique"
DETAIL:  Key (vlan)=(1) already exists.
@stveit stveit added the bug label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant