Can not create a subgroup if the name of the group already exists

Summary

Can not create a subgroup if the name of the group already exists as a (sub)group

Steps to reproduce

  1. Create a group tools
  2. Create a group playground
  3. Try to create a subgroup tools in the group playground.

What is the current bug behavior?

The subgroup tools is not created and an the HTML page 500 'Whoops, something went wrong on our end.' is displayed

What is the expected correct behavior?

Subgroup is created: playground\tools

Relevant logs and/or screenshots

From gitlab-rails\production.log

Started POST "/api/v4/jobs/request" for 10.9.102.37 at 2017-08-16 15:27:26 +0200
Started POST "/groups" for 10.9.100.154 at 2017-08-16 15:27:27 +0200
Processing by GroupsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"d0OAAmHkzOdcWtbPlWsTuLaTZTkYhkCCAefWKSyxF+MRKuQ8zCF8UjFOcFCKLviAl1SKlGQArosGZEkOU2TQmGQ==", "group"=>{"path"=>"tools", "parent_id"=>"44", "name"=>"tools", "description"=>"", "visibility_level"=>"10"}}
Completed 500 Internal Server Error in 36ms (ActiveRecord: 6.2ms | Elasticsearch: 0.0ms)

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_namespaces_on_name"
DETAIL:  Key (name)=(tools) already exists.
: INSERT INTO "namespaces" ("type", "name", "path", "visibility_level", "parent_id", "created_at", "updated_at", "description_html", "cached_markdown_version") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"):
  config/initializers/active_record_locking.rb:12:in `_create_record'
  app/services/groups/create_service.rb:36:in `execute'
  app/controllers/groups_controller.rb:32:in `create'
  lib/gitlab/i18n.rb:45:in `with_locale'
  lib/gitlab/i18n.rb:51:in `with_user_locale'
  app/controllers/application_controller.rb:298:in `set_locale'
  lib/gitlab/performance_bar/peek_performance_bar_with_rack_body.rb:16:in `call'
  lib/gitlab/middleware/multipart.rb:93:in `call'
  lib/gitlab/request_profiler/middleware.rb:14:in `call'
  lib/gitlab/middleware/go.rb:16:in `call'
  lib/gitlab/etag_caching/middleware.rb:11:in `call'
  lib/gitlab/middleware/readonly_geo.rb:30:in `call'
  lib/gitlab/request_context.rb:18:in `call'
  lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'

Results of GitLab environment info

Expand for output related to GitLab environment info

System information System: RedHatEnterpriseServer 6.9 Proxy: no Current User: git Using RVM: no Ruby Version: 2.3.3p222 Gem Version: 2.6.6 Bundler Version:1.13.7 Rake Version: 10.5.0 Redis Version: 3.2.5 Git Version: 2.13.0 Sidekiq Version:5.0.0 Go Version: unknown

GitLab information Version: 9.4.2-ee Revision: 421b9b5 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.3

Assignee Loading
Time tracking Loading