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

Move common functionality to destination base class #936

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

Conversation

hmpf
Copy link
Contributor

@hmpf hmpf commented Nov 11, 2024

Best reviewed per file.

@hmpf hmpf requested review from johannaengland, stveit and a team November 11, 2024 14:24
@hmpf hmpf changed the title move common functionality to base class Move common functionality to destination base class Nov 11, 2024
@hmpf hmpf self-assigned this Nov 12, 2024
@hmpf hmpf added the refactor label Nov 12, 2024
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from c39d564 to 55a2ff0 Compare November 13, 2024 09:23
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 55a2ff0 to 5989b0a Compare December 2, 2024 12:39
@hmpf hmpf marked this pull request as ready for review December 3, 2024 08:53
@hmpf hmpf requested a review from lunkwill42 December 3, 2024 08:53
@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 69.82249% with 51 lines in your changes missing coverage. Please review.

Project coverage is 76.70%. Comparing base (eaa3a25) to head (713e5d5).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/argus/notificationprofile/media/base.py 62.10% 36 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     #936      +/-   ##
==========================================
- Coverage   77.36%   76.70%   -0.66%     
==========================================
  Files         141      141              
  Lines        5548     5667     +119     
==========================================
+ Hits         4292     4347      +55     
- Misses       1256     1320      +64     

☔ 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.

@hmpf hmpf requested a review from stveit December 3, 2024 12:25
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 3b78212 to 7b8826c Compare December 4, 2024 06:51
@hmpf hmpf requested a review from johannaengland December 4, 2024 10:44
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 0e23752 to 3131826 Compare December 4, 2024 13:52
Copy link

sonarqubecloud bot commented Dec 4, 2024

Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

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

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not

We do have tests for when trying to change the medium that that will lead to an error

@hmpf
Copy link
Contributor Author

hmpf commented Dec 6, 2024

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not

We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

I guess the underlying problem is that we cannot lookup and change destinations of a specific media type directly, as part of the url of the endpoint. If we could, we would never need bother with media in the update-serializer.

@johannaengland
Copy link
Contributor

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not
We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

Yes, I agree, I can do this in another PR, but that would have to merged before this then, because it would show if the functionality is staying the same

@hmpf
Copy link
Contributor Author

hmpf commented Dec 6, 2024

I don't think it is wise to stress with finishing this PR this week anymore, so start on the patch-PR next week.

@hmpf hmpf requested a review from stveit January 7, 2025 09:36
@hmpf hmpf force-pushed the cleanup-destination-plugins branch 2 times, most recently from d1eb78c to 97cc505 Compare January 7, 2025 12:55
@hmpf
Copy link
Contributor Author

hmpf commented Jan 15, 2025

We could change the __str__ function of DestinationConfig change to use the get_label function in general. Then we can simplify this

Originally posted by @johannaengland in #1118 (comment)

@stveit
Copy link
Contributor

stveit commented Jan 15, 2025

I got stuff mostly working with this but the main problem is extracting errors to show in the related fields

@hmpf hmpf force-pushed the cleanup-destination-plugins branch from d329536 to ee9eb86 Compare January 16, 2025 07:27
@hmpf hmpf force-pushed the cleanup-destination-plugins branch 3 times, most recently from 38130e1 to 282b4d2 Compare January 24, 2025 11:01
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 282b4d2 to 304367b Compare January 24, 2025 11:29
@hmpf hmpf requested review from stveit and podliashanyk January 24, 2025 11:38
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.

Sum comments

return {}

@classmethod
def raise_if_not_deletable(cls, destination: DestinationConfig) -> NoneType:
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure None should be used as return type over NoneType, but this seems to be a relic from the past and not really introduced in this PR

@johannaengland johannaengland self-requested a review January 29, 2025 08:20

@classmethod
@abstractmethod
def has_duplicate(cls, queryset: QuerySet, settings: dict) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what @stveit mentioned in #1161 (review) could be avoided by simply updating the has_duplicate method to also take the instance and check, that the entered data is a duplicate of another destination than the given instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There need not exist an instance yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case instance can be empty and we know that if the settings exist somewhere else that it definitely is a duplicate

Copy link
Contributor Author

@hmpf hmpf Mar 11, 2025

Choose a reason for hiding this comment

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

We have that already, no? Smaller teaspoon, please.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we have the check that assures that no duplicate destinations are posted, but as @stveit said in his review - this leads to that error showing when updating a destination without changing the settings

Copy link
Contributor

Choose a reason for hiding this comment

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

@hmpf spin up #1161, create a destination and see how it behaves when you try to click update without changing things, or only changing one of the fields

Copy link
Contributor

@stveit stveit Mar 12, 2025

Choose a reason for hiding this comment

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

I think this issue if the only problem I have with this PR. I have admittedly only tested on #1161 which isnt completely up to date with the changes in this branch

@hmpf hmpf requested review from stveit and johannaengland March 10, 2025 11:51
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 532c71e to 0acb935 Compare March 13, 2025 10:33
@stveit
Copy link
Contributor

stveit commented Mar 14, 2025

Updating existing destination is still buggy. It allows me to update either the email on its own or the label and email together. it does not allow me to only update the label, or just click update without making any changes. In the cases where it doesnt work this is the server log error:

2025-03-14 11:57:19,231 django.request ERROR    Internal Server Error: /destinations/9/htmx-update/
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 58, in update_htmx
    form.save()
  File "/home/simon/repos/Argus/src/argus/htmx/destination/forms.py", line 37, in save
    self.serializer.save(user=self.request.user)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 180, in save
    assert not self.errors, (
AssertionError: You cannot call `.save()` on a serializer with invalid data.
2025-03-14 11:57:19,233 django.server INFO     "POST /destinations/9/htmx-update/ HTTP/1.1" 200 814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Changes requested
Development

Successfully merging this pull request may close these issues.

4 participants