Skip to content

The filter "approver" does not meet expectations when searching MR

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

Jihu Issue: #4656

When querying merge requests with filter Approver=user1, some merge requests that do NOT take user1 as an approver will be returned.

Steps to reproduce

Taking my own account @luzhiyuan.deer as an example:

  1. Create an approval rule: Let user @luzhiyuan.deer approve the main branch.

  2. Create an normal MR. The source branch is test-soure-branch, and the target branch is test-target-branch. This MR does not need the approval of @luzhiyuan.deer because the target branch is not main. This is cool :)

  3. Use the filter Approval=luzhiyuan.deer to query MR and find that the above MR is returned. This is not as expected!

  4. Furthermore, if we delete the approval rule in the 1st step and repeat the 3rd step at this time, we will see that MR can no longer be returned. This means that when searching MR, the approval rule in step 1 is wrongly used.

Example Project

https://gitlab.com/test-search-mr-by-approvers/project1/-/merge_requests/?sort=created_date&state=opened&approver%5B%5D=luzhiyuan.deer&first_page_size=20

What is the current bug behavior?

The result of querying the MR is not as expected.

What is the expected correct behavior?

The filter approver can be functioning normally.

Relevant logs and/or screenshots

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

I believe the problem is here: https://gitlab.com/gitlab-org/gitlab/-/blob/0f3b36669a5dad8b76a120cde106643b1ab5157b/ee/app/finders/merge_requests/by_approvers_finder.rb#L94

image

When we use approval rules, we should increase consideration for the target branch.

There are many related tables. They are too complex. I would very much like to hear your suggestions for fixing it. 🤯

Edited by 🤖 GitLab Bot 🤖