Commit eff38573 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '196172-issue-create-iid-conflict' into 'master'

Fixes #196172: manual IID should render conflict

Closes #196172

See merge request gitlab-org/gitlab!22788
parents 531bebc9 0bb54a0b
---
title: 'Fix Issue API: creating with manual IID returns conflict when IID already
in use'
merge_request: 22788
author: Mara Sophie Grosch
type: fixed
...@@ -220,6 +220,7 @@ module API ...@@ -220,6 +220,7 @@ module API
issue_params = convert_parameters_from_legacy_format(issue_params) issue_params = convert_parameters_from_legacy_format(issue_params)
begin
issue = ::Issues::CreateService.new(user_project, issue = ::Issues::CreateService.new(user_project,
current_user, current_user,
issue_params.merge(request: request, api: true)).execute issue_params.merge(request: request, api: true)).execute
...@@ -233,6 +234,9 @@ module API ...@@ -233,6 +234,9 @@ module API
else else
render_validation_error!(issue) render_validation_error!(issue)
end end
rescue ::ActiveRecord::RecordNotUnique
render_api_error!('Duplicated issue', 409)
end
end end
desc 'Update an existing issue' do desc 'Update an existing issue' do
......
...@@ -160,6 +160,16 @@ describe API::Issues do ...@@ -160,6 +160,16 @@ describe API::Issues do
expect(json_response['iid']).not_to eq 9001 expect(json_response['iid']).not_to eq 9001
end end
end end
context 'when an issue with the same IID exists on database' do
it 'returns 409' do
post api("/projects/#{project.id}/issues", admin),
params: { title: 'new issue', iid: issue.iid }
expect(response).to have_gitlab_http_status(409)
expect(json_response['message']).to eq 'Duplicated issue'
end
end
end end
it 'creates a new project issue' do it 'creates a new project issue' 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