Commit 0923ef93 authored by Patrick Bajao's avatar Patrick Bajao

Clear cached merge_ref_sha on reopen

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41572, we
started caching `merge_ref_sha` when we clean up the merge request
refs.

It is possible to re-open a closed MR though. If we don't clear
the cached `merge_ref_sha`, `MergeRequest#merge_ref_head` will
always point to the cached one which can be stale.

This fixes that by clearing the cached value on reopen.
parent e4b4a34b
...@@ -16,6 +16,7 @@ module MergeRequests ...@@ -16,6 +16,7 @@ module MergeRequests
merge_request.update_project_counter_caches merge_request.update_project_counter_caches
merge_request.cache_merge_request_closes_issues!(current_user) merge_request.cache_merge_request_closes_issues!(current_user)
merge_request.cleanup_schedule&.destroy merge_request.cleanup_schedule&.destroy
merge_request.update_column(:merge_ref_sha, nil)
end end
merge_request merge_request
......
---
title: Clear cached merge_ref_sha on reopen
merge_request: 47747
author:
type: fixed
...@@ -24,6 +24,7 @@ RSpec.describe MergeRequests::ReopenService do ...@@ -24,6 +24,7 @@ RSpec.describe MergeRequests::ReopenService do
before do before do
allow(service).to receive(:execute_hooks) allow(service).to receive(:execute_hooks)
merge_request.create_cleanup_schedule(scheduled_at: Time.current) merge_request.create_cleanup_schedule(scheduled_at: Time.current)
merge_request.update_column(:merge_ref_sha, 'abc123')
perform_enqueued_jobs do perform_enqueued_jobs do
service.execute(merge_request) service.execute(merge_request)
...@@ -48,6 +49,10 @@ RSpec.describe MergeRequests::ReopenService do ...@@ -48,6 +49,10 @@ RSpec.describe MergeRequests::ReopenService do
expect(merge_request.reload.cleanup_schedule).to be_nil expect(merge_request.reload.cleanup_schedule).to be_nil
end end
it 'clears the cached merge_ref_sha' do
expect(merge_request.reload.merge_ref_sha).to be_nil
end
context 'note creation' do context 'note creation' do
it 'creates resource state event about merge_request reopen' do it 'creates resource state event about merge_request reopen' do
event = merge_request.resource_state_events.last event = merge_request.resource_state_events.last
......
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