Custom Templates - Incorrect template used when creating project

Summary

When clicking on the "Use template" button next to a template, a different by similarly named project template is used instead. The "Preview" button does go to the correct project.

Steps to reproduce

Videos of the issue can be found in ZenDesk ticket # 111338 (internal link).

User has multiple templates with similar names:

  • Docker App
  • Docker Image
  • Docker Image and App

These steps consistently reproduce the user's instance:

  1. Go into the create new project flow
  2. Select Create from template
  3. Select Instance
  4. Click Use Template next to "Docker Image" and complete the project creation
  5. Project is created successfully, but using the "Docker App" template

Example Project

An export of the project templates can be found in ZenDesk ticket # 111338 (internal link).

What is the current bug behavior?

User selects "Docker Image", but the "Docker App" template is used.

What is the expected correct behavior?

The template selected is used to create the project.

Relevant logs and/or screenshots

 Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "project"=>{"template_name"=>"Docker Image", "use_custom_template"=>"true", "group_with_project_templates_id"=>"", "ci_cd_only"=>"false", "name"=>"demo", "namespace_id"=>"3", "path"=>"demo", "description"=>"", "visibility_level"=>"20"}}
Error writing to .git/config for project user.name/demo (251): repository does not exist.
Export job started for project ID 226 with job ID 4e46548e26038328a6a9d918
Redirected to https://gitlab.domain.com/user.name/demo
Completed 302 Found in 123ms (ActiveRecord: 39.0ms | Elasticsearch: 0.0ms)
Saved project export /var/opt/gitlab/gitlab-rails/shared/tmp/project_exports/devops/templates/docker-app/2019-01-08_18-47-171_devops_templates_docker-app_export.tar.gz
Import/Export - Project Docker App with ID: 226 successfully exported

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 2.5.3p105 Gem Version: 2.7.6 Bundler Version:1.16.6 Rake Version: 12.3.1 Redis Version: 3.2.12 Git Version: 2.18.1 Sidekiq Version:5.2.3 Go Version: unknown

GitLab information Version: 11.6.3-ee Revision: 76c33c6 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.11 URL: https://gitlab.domain.com HTTP Clone URL: https://gitlab.domain.com/some-group/some-project.git SSH Clone URL: ssh://git@gitlab.domain.com:2222/some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: yes Using Omniauth: yes Omniauth Providers:

GitLab Shell Version: 8.4.3 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks 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 >= 8.4.3 ? ... OK (8.4.3) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK

Access to /var/opt/gitlab/.ssh/authorized_keys: 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: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) (removed)

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/2 ... yes 5/5 ... yes 16/6 ... yes 16/9 ... yes 16/10 ... yes 5/16 ... yes 5/17 ... yes 20/20 ... yes 20/21 ... yes 21/22 ... yes 21/23 ... yes 3/24 ... yes 24/25 ... yes 24/26 ... yes 24/28 ... yes 20/29 ... yes 16/30 ... yes 27/31 ... yes 27/32 ... yes 28/33 ... yes 28/35 ... yes 21/36 ... yes 3/38 ... yes 28/39 ... yes 58/40 ... yes 16/42 ... yes 46/45 ... yes 38/48 ... yes 38/50 ... yes 20/51 ... yes 53/52 ... yes 53/53 ... yes 53/54 ... yes 53/55 ... yes 53/56 ... yes 39/57 ... yes 38/58 ... yes 16/59 ... yes 16/61 ... yes 53/65 ... yes 68/66 ... yes 58/72 ... yes 58/102 ... yes 68/103 ... yes 57/104 ... yes 68/111 ... yes 14/114 ... yes 38/115 ... yes 38/120 ... yes 53/122 ... yes 53/123 ... yes 28/124 ... yes 28/125 ... yes 53/131 ... yes 65/132 ... yes 53/136 ... yes 53/137 ... yes 38/139 ... yes 24/141 ... yes 53/142 ... yes 16/144 ... yes 54/147 ... yes 53/148 ... yes 24/155 ... yes 35/157 ... yes 5/160 ... yes 5/161 ... yes 16/162 ... yes 65/164 ... yes 23/166 ... yes 24/170 ... yes 60/172 ... yes 60/173 ... yes 70/174 ... yes 35/176 ... yes 24/177 ... yes 24/179 ... yes 24/180 ... yes 23/181 ... yes 23/183 ... yes 65/185 ... yes 57/187 ... yes 23/188 ... yes 23/189 ... yes 38/190 ... yes 71/196 ... yes 53/198 ... yes 58/202 ... yes 58/204 ... yes 3/205 ... yes 23/206 ... yes 23/208 ... yes 23/209 ... yes 66/210 ... yes 3/211 ... yes 65/212 ... yes 65/213 ... yes 35/216 ... yes 65/217 ... yes 65/218 ... yes 69/219 ... yes 65/220 ... yes 65/223 ... yes 24/224 ... yes 65/225 ... yes 53/226 ... yes 23/227 ... yes 65/228 ... yes 53/230 ... yes 66/231 ... yes 23/232 ... yes 53/240 ... yes 65/247 ... yes 66/253 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.5.3) Git version >= 2.18.0 ? ... yes (2.18.1) Git user has default SSH configuration? ... yes Active users: ... 38 Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes

It appears that in some cases the results returned from available_custom_project_templates are not the expected order and can include projects that are missing some of the search terms.

On my own instance I was unable to reproduce the error in the UI, but could induce inconsistent search results from the rails console. I only saw this if I passed a certain subgroup_id, which is a slightly different scenario from the user's, but I believe we are seeing the same underlying problem.

# Docker App is the first result, ahead of the intended project
irb(main):012:0> u.available_custom_project_templates(search: "Docker Image", subgroup_id: 2)
=> #<ActiveRecord::Relation [#<Project id:5 test_group/docker-app>, #<Project id:6 test_group/docker-image>]>

# Docker App not returned at all, as expected
irb(main):013:0> u.available_custom_project_templates(search: "Docker Image")
=> #<ActiveRecord::Relation [#<Project id:12 test_group/project-templates/docker-image>, #<Project id:24 test_group/project-templates/docker-image-and-app>]>

From the user's Rails console:

irb(main):001:0> u = User.find_by_name('User Name') 
=> #<User id:2 @username> 
irb(main):002:0> u.available_custom_project_templates(search: "Docker App", subgroup_id: nil) 
=> #<ActiveRecord::Relation [#<Project id:226 devops/templates/docker-app>, #<Project id:198 devops/templates/docker-image-app>]> 
# Docker App returned but Docker Image is not
irb(main):003:0> u.available_custom_project_templates(search: "Docker Image", subgroup_id: nil) 
=> #<ActiveRecord::Relation [#<Project id:226 devops/templates/docker-app>, #<Project id:131 devops/templates/docker-image>, #<Project id:198 devops/templates/docker-image-app>, #<Project id:137 devops/templates/docker-compose-stack>]> 
# Docker App returned ahead of Docker Image and App
irb(main):004:0> u.available_custom_project_templates(search: "Docker Image and App", subgroup_id: nil) 
=> #<ActiveRecord::Relation [#<Project id:226 devops/templates/docker-app>, #<Project id:198 devops/templates/docker-image-app>]> 
irb(main):005:0>

template_project - create_from_template_service.rb#L31-32

available_custom_project_templates - user.rb#133-140

/cc @fjsanpedro

Edited Jan 10, 2019 by Will Chandler (ex-GitLab)
Assignee Loading
Time tracking Loading