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

Use forms in destination page #1161

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

hmpf
Copy link
Contributor

@hmpf hmpf commented Jan 23, 2025

Depends on #936

Review file by file

Will be squashed

@hmpf hmpf requested review from stveit and johannaengland January 23, 2025 12:40
@hmpf hmpf force-pushed the destination-with-forms branch 6 times, most recently from a51d4e7 to b1c02c5 Compare January 24, 2025 11:32
@hmpf hmpf marked this pull request as ready for review January 24, 2025 11:32
@hmpf hmpf self-assigned this Jan 24, 2025
@hmpf hmpf added the frontend Affects frontend label Jan 24, 2025
@hmpf hmpf force-pushed the destination-with-forms branch from b1c02c5 to b4c8a33 Compare January 24, 2025 11:35
@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 49.15825% with 151 lines in your changes missing coverage. Please review.

Project coverage is 77.07%. Comparing base (eaa3a25) to head (bbebc2e).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/argus/htmx/destination/views.py 16.94% 98 Missing ⚠️
src/argus/notificationprofile/media/base.py 63.10% 38 Missing ⚠️
src/argus/notificationprofile/media/email.py 80.95% 8 Missing ⚠️
src/argus/notificationprofile/media/__init__.py 42.85% 4 Missing ⚠️
src/argus/notificationprofile/serializers.py 89.47% 2 Missing ⚠️
...rc/argus/notificationprofile/media/sms_as_email.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1161      +/-   ##
==========================================
- Coverage   77.36%   77.07%   -0.29%     
==========================================
  Files         141      140       -1     
  Lines        5548     5675     +127     
==========================================
+ Hits         4292     4374      +82     
- Misses       1256     1301      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@stveit stveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some issues while testing this:

Trying to update a destination gives the error "This email destination already exists." This happens if you make no changes to the form and click "update", or only change either label or the setting. But if you change both to unique values that are not used in another destination, then it updates. It seems like the validation doesn't understand that the updated destination will replace the original, and just treats it like you're trying to create a new destination with the same label and or setting.

Simultaneously, a new collapse elements is created that is empty with the title (0)

image

Another problem (relevant comment here is when you try to create a new destination (or update) with a label or email that collides with an existing destination, you get the error message "This email destination already exists", but it does not indicate in any way if the problem is the label, the email or both

@hmpf hmpf added the blocked Another thing/issue has to be resolved before tackling this label Mar 10, 2025
{% with update=label_form.instance.pk %}
{% csrf_token %}
<fieldset class="p-2 border rounded-box border{% if not update %}-primary{% endif %} items-center gap-4 flex flex-col items-end justify-center">
{% if not label_form.instance.pk %}<legend class="menu-title">Create destination</legend>{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% if not label_form.instance.pk %}<legend class="menu-title">Create destination</legend>{% endif %}
{% if not update %}<legend class="menu-title">Create destination</legend>{% endif %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"update" does not exist in the context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, why is that? I thought it is available everywhere that is framed by the {% with update=label_form.instance.pk %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking context sent by the view. Fooled by github diff view again.

@hmpf hmpf force-pushed the destination-with-forms branch from bf5af7b to 58fe34d Compare March 13, 2025 10:35
@hmpf hmpf force-pushed the destination-with-forms branch from c7ac6be to 014c962 Compare March 13, 2025 14:50
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@stveit
Copy link
Contributor

stveit commented Mar 14, 2025

Immediate problem I noticed here: If you try to create a new destination that should fail (has same label or email has a pre-existing destination), it does not give an error message. The form is emptied and a success message appears, like it does when you actually succesfulyl create a destination, but no new destination is added.

Edit: If both fields are indentical to a pre existing email it gives the success message, if only the label is duplicate but email is new, it gives an error An error occured while processing your request, please try again, and the server log shows this:

2025-03-14 11:50:47,762 django.request ERROR    Internal Server Error: /destinations/email/create/
Traceback (most recent call last):
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "unique_label_per_user_and_medium"
DETAIL:  Key (user_id, media_id, label)=(2, email, myemial22) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/views/decorators/http.py", line 64, in inner
    return func(request, *args, **kwargs)
  File "/home/simon/repos/Argus/src/argus/htmx/destination/views.py", line 107, in create_destination
    obj, changed = save_forms(request.user, media, label_form, settings_form)
  File "/home/simon/repos/Argus/src/argus/htmx/destination/views.py", line 88, in save_forms
    obj.save()
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save
    self.save_base(
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/base.py", line 998, in save_base
    updated = self._save_table(
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1161, in _save_table
    results = self._do_insert(
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1202, in _do_insert
    return manager._insert(
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1847, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1836, in execute_sql
    cursor.execute(sql, params)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "unique_label_per_user_and_medium"
DETAIL:  Key (user_id, media_id, label)=(2, email, myemial22) already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Another thing/issue has to be resolved before tackling this frontend Affects frontend
Projects
Status: Changes requested
Development

Successfully merging this pull request may close these issues.

4 participants