Commit 77b59525 authored by Sean McGivern's avatar Sean McGivern

Fix 500 error when editing conflicts with approvals enabled

When an MR or issue and there's a conflict, we rescue the StaleObjectError and
render the edit page again. However, for MRs in EE, we need to ensure that
@suggested_approvers is set before that happens, otherwise the view will fail to
render.
parent 6b930bd2
...@@ -311,6 +311,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -311,6 +311,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
end end
rescue ActiveRecord::StaleObjectError rescue ActiveRecord::StaleObjectError
set_suggested_approvers if request.format.html?
render_conflict_response render_conflict_response
end end
......
---
title: Fix 500 error when approvals are enabled and editing an MR conflicts with another
edit
merge_request:
author:
...@@ -456,6 +456,12 @@ describe Projects::MergeRequestsController do ...@@ -456,6 +456,12 @@ describe Projects::MergeRequestsController do
it_behaves_like 'update invalid issuable', MergeRequest it_behaves_like 'update invalid issuable', MergeRequest
end end
context 'when the merge request requires approval' do
before { project.update_attributes(approvals_before_merge: 1) }
it_behaves_like 'update invalid issuable', MergeRequest
end
context 'the approvals_before_merge param' do context 'the approvals_before_merge param' do
before { project.update_attributes(approvals_before_merge: 2) } before { project.update_attributes(approvals_before_merge: 2) }
......
...@@ -30,6 +30,10 @@ shared_examples 'update invalid issuable' do |klass| ...@@ -30,6 +30,10 @@ shared_examples 'update invalid issuable' do |klass|
expect(response).to render_template(:edit) expect(response).to render_template(:edit)
expect(assigns[:conflict]).to be_truthy expect(assigns[:conflict]).to be_truthy
if klass == MergeRequest && issuable.requires_approve?
expect(assigns[:suggested_approvers]).to be_an(Array)
end
end end
it 'renders json error message when format is json' do it 'renders json error message when format is json' 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