Skip to content

Refactor deletion of dangling labels #1606

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

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Refactor deletion of dangling labels #1606

merged 2 commits into from
Oct 15, 2024

Conversation

MrSerth
Copy link
Member

@MrSerth MrSerth commented Aug 25, 2024

The previous mechanism required newly-assigned TaskLabels to be saved before aiming to destroy dangling labels. However, there is one edge-case previously used in the tests which caused erroneous behavior:

Imagine, there is a dangling label (with no matching TaskLabel). Then, a task is assigned that dangling label through the label_names= mechanism. This will cause the Label.find_or_initialize_by(name:) method to return the dangling label and assign that to the task. However, when this assignment is not saved it (and no TaskLabel record is created), the following call to destroy dangling labels also removed the one just assigned to a task.

This caused errors in tests, when switching from labels to label_names in the TaskController specs to remove the use of unpermitted parameters and transactional fixtures.

The new mechanism will still remove dangling labels, but only those associated with a TaskLabel just removed. Through the transactional setting of destroy hooks, this still ensures there aren't any leftovers.

@MrSerth MrSerth added bug ruby Pull requests that update Ruby code labels Aug 25, 2024
@MrSerth MrSerth requested review from Dome-GER and Mathis-Z August 25, 2024 10:46
@MrSerth MrSerth self-assigned this Aug 25, 2024
Copy link

codecov bot commented Aug 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.78%. Comparing base (a271eed) to head (815c20a).
Report is 44 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1606   +/-   ##
=======================================
  Coverage   94.77%   94.78%           
=======================================
  Files         130      130           
  Lines        3330     3334    +4     
=======================================
+ Hits         3156     3160    +4     
  Misses        174      174           

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

Copy link
Contributor

@Mathis-Z Mathis-Z left a comment

Choose a reason for hiding this comment

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

Looks good, I am just wondering if we need Label#to_s? I could not find any usage and it is also not covered by the tests.

@MrSerth
Copy link
Member Author

MrSerth commented Aug 26, 2024

Looks good, I am just wondering if we need Label#to_s? I could not find any usage and it is also not covered by the tests.

I knew you would point that out. It is not used, that's right. I found it helpful to have while debugging, since it replaced the magic object ID with the actual label name when printing. If you like, I can add a simple test for that.

@Mathis-Z
Copy link
Contributor

The test is a bit silly 😉 but at least Codecov is happy now 👍

MrSerth added a commit that referenced this pull request Sep 11, 2024
We recently discovered an edge case where a moved file was not updated correctly. At first, it got removed and recreated, and later on only removed. While these changes look pretty difficult, they are the best and only working approach I could find to fix the problem ;). For now, I'd suggest to go with this solution. See #1606 for more details.
kkoehn pushed a commit that referenced this pull request Sep 16, 2024
We recently discovered an edge case where a moved file was not updated correctly. At first, it got removed and recreated, and later on only removed. While these changes look pretty difficult, they are the best and only working approach I could find to fix the problem ;). For now, I'd suggest to go with this solution. See #1606 for more details.
kkoehn pushed a commit that referenced this pull request Sep 17, 2024
We recently discovered an edge case where a moved file was not updated correctly. At first, it got removed and recreated, and later on only removed. While these changes look pretty difficult, they are the best and only working approach I could find to fix the problem ;). For now, I'd suggest to go with this solution. See #1606 for more details.
The previous mechanism required newly-assigned TaskLabels to be saved before aiming to destroy dangling labels. However, there is one edge-case previously used in the tests which caused erroneous behavior:

Imagine, there is a dangling label (with no matching TaskLabel). Then, a task is assigned that dangling label through the `label_names=` mechanism. This will cause the `Label.find_or_initialize_by(name:)` method to return the dangling label and assign that to the task. However, when this assignment is not saved it (and no `TaskLabel` record is created), the following call to destroy dangling labels also removed the one just assigned to a task.

This caused errors in tests, when switching from `labels` to `label_names` in the TaskController specs to remove the use of unpermitted parameters and transactional fixtures.

The new mechanism will still remove dangling labels, but only those associated with a TaskLabel just removed. Through the transactional setting of destroy hooks, this still ensures there aren't any leftovers.
Since a label is considered "unique" based on its name, overwriting `to_s` makes sense to aid debugging.
@Dome-GER Dome-GER merged commit 4ad3ca4 into master Oct 15, 2024
13 checks passed
@Dome-GER Dome-GER deleted the label_fixes branch October 15, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants