Promoting a label breaks when there is a duplicate named label in the parent group and board lists with the label to be promoted in a project issue board
Summary
- A 500 error is thrown when trying to promote a label with the same name in a parent group and a project board has a list with the label to be promoted.
- When there is a group label with the same name as a project label, and both are applied to a project issue, promoting the project label does not remove the now non-existent project label from the issue.
Steps to reproduce
1:
- Create a project label named
Foo
- Create a label named
Foo
in the immediate parent group. - Within the project, create a board and add a list for each
Foo
label. - Go to the project label list and try to promote the project label
Foo
to the parent group.
2:
- Create project label named
Foo
- Create group label named
Foo
- Assign both labels to a project issue.
- Promote the project label to the parent group.
- Open the project issue and notice that there are two
Foo
labels still present.
Example Project
https://gitlab.com/tech-marketing/demos/gitlab-agile-demo/awesome-co/ops/-/labels -- label here is In SIT
.
What is the current bug behavior?
- 500 error
- Duplicate labels on the issue
What is the expected correct behavior?
- List with project label
Foo
now uses Group labelFoo
when promoting. If twoFoo
lists are present (group label, project label), then the all issues in the project label list become visible in the group labelFoo
list and the projectFoo
list is removed. - Non-existed project label is not visible on the issue.
Relevant logs and/or screenshots
Backtrace:
lib/gitlab/database/load_balancing/connection_proxy.rb:120:in `block in write_using_load_balancer', lib/gitlab/database/load_balancing/load_balancer.rb:122:in `block in read_write', lib/gitlab/database/load_balancing/load_balancer.rb:200:in `retry_with_backoff', lib/gitlab/database/load_balancing/load_balancer.rb:118:in `read_write', lib/gitlab/database/load_balancing/connection_proxy.rb:119:in `write_using_load_balancer', lib/gitlab/database/load_balancing/connection_proxy.rb:61:in `block (2 levels) in <class:ConnectionProxy>', app/services/labels/promote_service.rb:77:in `update_issue_board_lists', app/services/labels/promote_service.rb:31:in `update_old_label_relations', ee/app/services/ee/labels/promote_service.rb:12:in `update_old_label_relations', app/services/labels/promote_service.rb:17:in `block (2 levels) in execute', app/services/labels/promote_service.rb:16:in `block in execute', app/models/concerns/cross_database_modification.rb:92:in `block in transaction', lib/gitlab/database/load_balancing/connection_proxy.rb:120:in `block in write_using_load_balancer', lib/gitlab/database/load_balancing/load_balancer.rb:122:in `block in read_write', lib/gitlab/database/load_balancing/load_balancer.rb:200:in `retry_with_backoff', lib/gitlab/database/load_balancing/load_balancer.rb:118:in `read_write', lib/gitlab/database/load_balancing/connection_proxy.rb:119:in `write_using_load_balancer', lib/gitlab/database/load_balancing/connection_proxy.rb:71:in `transaction', lib/gitlab/database.rb:332:in `block in transaction', lib/gitlab/database.rb:331:in `transaction', app/models/concerns/cross_database_modification.rb:83:in `transaction', app/services/labels/promote_service.rb:12:in `execute', app/controllers/projects/labels_controller.rb:123:in `promote', ee/lib/gitlab/ip_address_state.rb:10:in `with', ee/app/controllers/ee/application_controller.rb:45:in `set_current_ip_address', app/controllers/application_controller.rb:530:in `set_current_admin', lib/gitlab/session.rb:11:in `with_session', app/controllers/application_controller.rb:521:in `set_session_storage', lib/gitlab/i18n.rb:107:in `with_locale', lib/gitlab/i18n.rb:113:in `with_user_locale', app/controllers/application_controller.rb:515:in `set_locale', app/controllers/application_controller.rb:509:in `set_current_context', ee/lib/omni_auth/strategies/group_saml.rb:41:in `other_phase', lib/gitlab/metrics/elasticsearch_rack_middleware.rb:16:in `call', lib/gitlab/middleware/memory_report.rb:13:in `call', lib/gitlab/middleware/speedscope.rb:13:in `call', lib/gitlab/database/load_balancing/rack_middleware.rb:23:in `call', lib/gitlab/middleware/rails_queue_duration.rb:33:in `call', lib/gitlab/metrics/rack_middleware.rb:16:in `block in call', lib/gitlab/metrics/web_transaction.rb:46:in `run', lib/gitlab/metrics/rack_middleware.rb:16:in `call', lib/gitlab/jira/middleware.rb:19:in `call', lib/gitlab/middleware/go.rb:20:in `call', lib/gitlab/etag_caching/middleware.rb:21:in `call', lib/gitlab/middleware/query_analyzer.rb:11:in `block in call', lib/gitlab/database/query_analyzer.rb:37:in `within', lib/gitlab/middleware/query_analyzer.rb:11:in `call', lib/gitlab/middleware/multipart.rb:173:in `call', lib/gitlab/middleware/read_only/controller.rb:50:in `call', lib/gitlab/middleware/read_only.rb:18:in `call', lib/gitlab/middleware/same_site_cookies.rb:27:in `call', lib/gitlab/middleware/handle_malformed_strings.rb:21:in `call', lib/gitlab/middleware/basic_health_check.rb:25:in `call', lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call', lib/gitlab/middleware/request_context.rb:21:in `call', lib/gitlab/middleware/webhook_recursion_detection.rb:15:in `call', config/initializers/fix_local_cache_middleware.rb:11:in `call', lib/gitlab/middleware/compressed_json.rb:26:in `call', lib/gitlab/middleware/rack_multipart_tempfile_factory.rb:19:in `call', lib/gitlab/middleware/sidekiq_web_static.rb:20:in `call', lib/gitlab/metrics/requests_rack_middleware.rb:77:in `call', lib/gitlab/middleware/release_env.rb:13:in `call'
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_lists_on_board_id_and_label_id"
DETAIL: Key (board_id, label_id)=(4523596, 27642475) already exists.
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
Bug happens in Projects::LabelsController#promote