Issue create via API with manual IID: 500 instead of 409
Summary
When using the issue API to create issues with a given IID, the server returns status code 500 when the IID is already in use. I would have expected to get a 409 response.
Steps to reproduce
- Create issue via issue API with manually given IID
- Create another issue via issue API with the same IID
What is the current bug behavior?
When IID is already in use, the server returns a HTTP 500 status code and the message "500 Internal Server Error".
What is the expected correct behavior?
When the IID is already in use, the server should return a HTTP 409 (Conflict) response.
Relevant logs and/or screenshots
{"time":"2020-01-10T14:46:05.719Z","severity":"INFO","duration":131.38,"db":32.15,"view":99.22999999999999,"status":500,"method":"POST","path":"/api/v4/projects/42/issues","params":[{"key":"iid","value":null},{"key":"title","value":"[FILTERED]"},{"key":"description","value":"[FILTERED]"},{"key":"labels","value":["priority-s3","category-dashlog","enhancement"]},{"key":"due_date","value":"2020-01-17"}],"host":"carnets42.carnet02.de","remote_ip":"127.0.0.1, 127.0.0.1","ua":"requests-scala","route":"/api/:version/projects/:id/issues","user_id":1,"username":"root","exception.class":"ActiveRecord::RecordNotUnique","exception.message":"PG::UniqueViolation: ERROR: duplicate key value violates unique constraint \"index_issues_on_project_id_and_iid\"\nDETAIL: Key (project_id, iid)=(42, 30496) already exists.\n: INSERT INTO \"issues\" (\"title\", \"author_id\", \"project_id\", \"created_at\", \"updated_at\", \"description\", \"iid\", \"due_date\", \"title_html\", \"description_html\", \"relative_position\", \"cached_markdown_version\", \"lock_version\", \"time_estimate\") VALUES ('(stripped)', 1, 42, '2020-01-10 14:46:05.678928', '2020-01-10 14:46:05.678928', '(stripped)', 30496, '2020-01-17', '(stripped)', '(stripped)', 1073761791, 1179648, 0, 0) RETURNING \"id\"","exception.backtrace":["app/services/issuable_base_service.rb:167:in `block in create'","app/services/issuable_base_service.rb:166:in `create'","app/services/issues/create_service.rb:14:in `execute'","lib/api/issues.rb:232:in `block (2 levels) in <class:Issues>'","lib/api/api_guard.rb:168:in `call'"],"queue_duration":47.11,"correlation_id":"PwTZyOEfjZ"}
Some data was stripped by me because of confidential information.
Output of checks
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Debian 10 Current User: git Using RVM: no Ruby Version: 2.6.3p62 Gem Version: 2.7.9 Bundler Version:1.17.3 Rake Version: 12.3.3 Redis Version: 3.2.12 Git Version: 2.24.1 Sidekiq Version:5.2.7 Go Version: unknownGitLab information Version: 12.6.2 Revision: 3041661dec5 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 10.9 URL: https://gitlab.carnet02.de HTTP Clone URL: https://gitlab.carnet02.de/some-group/some-project.git SSH Clone URL: git@carnets42:some-group/some-project.git Using LDAP: yes Using Omniauth: yes Omniauth Providers: google_oauth2
GitLab Shell Version: 10.3.0 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 10.3.0 ? ... OK (10.3.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Checking Reply by email ...
IMAP server credentials are correct? ... yes Init.d configured correctly? ... skipped MailRoom running? ... skipped
Checking Reply by email ... Finished
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... Server: ldapmain not verifying SSL hostname of LDAPS server 'carnet02.de:636' LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) User output sanitized. Found 31 users of 100 limit.
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 2/3 ... yes 2/4 ... yes 5/5 ... yes 5/6 ... yes 5/7 ... yes 5/8 ... yes 6/9 ... yes 7/11 ... yes 5/12 ... yes 5/13 ... yes 5/14 ... yes 7/15 ... yes 5/16 ... yes 7/17 ... yes 39/18 ... yes 39/19 ... yes 43/20 ... yes 16/21 ... yes 5/23 ... yes 39/24 ... yes 18/25 ... yes 19/26 ... yes 16/27 ... yes 16/28 ... yes 2/29 ... yes 21/30 ... yes 7/31 ... yes 40/32 ... yes 39/33 ... yes 28/34 ... yes 2/35 ... yes 27/36 ... yes 29/37 ... yes 8/40 ... yes 7/41 ... yes 7/42 ... yes 7/43 ... yes 7/44 ... yes 42/45 ... yes 60/46 ... yes 2/47 ... yes 43/50 ... yes 39/51 ... yes 39/52 ... yes 44/53 ... yes 23/54 ... yes 45/55 ... yes 34/56 ... yes 20/57 ... yes 2/58 ... yes 8/59 ... yes 22/62 ... yes 22/63 ... yes 22/64 ... yes 40/65 ... yes 45/66 ... yes 39/67 ... yes 47/68 ... yes 22/69 ... yes 45/70 ... yes 45/71 ... yes 45/72 ... yes 41/73 ... yes 29/74 ... yes 40/75 ... yes 45/76 ... yes 40/77 ... yes 40/78 ... yes 40/79 ... yes 50/80 ... yes 22/81 ... yes 40/82 ... yes 50/83 ... yes 50/84 ... yes 50/85 ... yes 50/86 ... yes 50/87 ... yes 42/88 ... yes 43/89 ... yes 43/90 ... yes 51/91 ... yes 51/92 ... yes 52/93 ... yes 53/94 ... yes 53/95 ... yes 22/96 ... yes 40/97 ... yes 40/98 ... yes 41/99 ... yes 46/100 ... yes 40/101 ... yes 55/102 ... yes 40/103 ... yes 55/104 ... yes 55/105 ... yes 57/106 ... yes 57/107 ... yes 56/108 ... yes 54/109 ... yes 39/110 ... yes 40/111 ... yes 45/112 ... yes 58/113 ... yes 58/114 ... yes 59/115 ... yes 59/116 ... yes 60/118 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.5.3 ? ... yes (2.6.3) Git version >= 2.22.0 ? ... yes (2.24.1) Git user has default SSH configuration? ... yes Active users: ... 19 Is authorized keys file accessible? ... yes
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished