Cannot delete labels that are on lots of issues
Summary
If you click on the delete label button for a label that is assigned to lots of issues, the site sits there for some time and then reports an error. The label doesn't seem to have been removed from any issues if you keep a search open in another window.
Steps to reproduce
Try to delete the ~"Verify [DEPRECATED]" or ~"CI/CD [DEPRECATED]" labels from the gitlab-org
group (you are welcome to try, these are the labels that I am trying to delete.)
Example Project
gitlab-org
What is the current bug behavior?
Labels not deleted, error page returned
What is the expected correct behavior?
Labels deleted, no error page
Possible fixes
We do have these two problem lines:
- https://gitlab.com/gitlab-org/gitlab/blob/v12.3.0-ee/app%2Fmodels%2Flabel.rb#L19
- https://gitlab.com/gitlab-org/gitlab/blob/v12.3.0-ee/app%2Fmodels%2Flabel.rb#L21
These both say that when we delete a label, we need to load every list and link it has, and delete that.
This is not good practice: that's why both those lines have rubocop:disable Cop/ActiveRecordDependent
, as we don't allow that any more. It's a legacy problem. https://docs.gitlab.com/ee/development/foreign_keys.html#dependent-removals has more information.
In this case, LabelLink
has no destroy hooks, so we could probably just replace that with delete
right now.
List
does have a hook, but it would never run for a label list (they are always destroyable): https://gitlab.com/gitlab-org/gitlab/blob/v12.3.0-ee/app%2Fmodels%2Flist.rb#L19