Commit 5ec2461f authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Filter out duplicates from the finder by related commit sha

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/21686

**Problem**

We discovered an edge case when the same merge request can be returned
multiple times. If the project has `always squash` option on, then we
create a squash commit even for merge requests with only one
commit. In this case, the commit from the merge request is a squash
commit at the same time.

**Solution**

Use UNION instead of UNION ALL to remove duplicated records.
parent 66e899b6
......@@ -270,8 +270,7 @@ class MergeRequest < ApplicationRecord
by_commit_sha(sha),
by_squash_commit_sha(sha),
by_merge_commit_sha(sha)
],
remove_duplicates: false
]
)
end
scope :by_cherry_pick_sha, -> (sha) do
......
---
title: Remove duplicates from related_commit_sha query
merge_request: 51888
author:
type: fixed
......@@ -451,6 +451,17 @@ RSpec.describe MergeRequest, factory_default: :keep do
it { is_expected.to be_empty }
end
context 'when commit is part of the merge request and a squash commit at the same time' do
let!(:merge_request) { create(:merge_request, :with_diffs) }
let(:sha) { merge_request.commits.first.id }
before do
merge_request.update!(squash_commit_sha: sha)
end
it { is_expected.to eq([merge_request]) }
end
end
describe '.by_cherry_pick_sha' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment