500 Error when accessing a todo list with references to a deleted project
Summary
If a user tries to access {GITLAB_HOST}/dashboard/todos after a project containing issues linked to this user has been deleted, he/she receives a 500 Error page and an error is logged in gitlab-rails/production.log
Steps to reproduce
- Create a project
- Create an issue and assign it to user A or simply mention user A
- Delete the project
- Login as user A
- Try to display the Todos list
- A 500 error is displayed
What is the current bug behavior?
Display a 500 Error page.
What is the expected correct behavior?
Display a list of Todos
Relevant logs and/or screenshots
The following is logged in gitlab-rails/production.log:
Started GET "/apps/gitlab/dashboard/todos" for 139.191.71.19 at 2018-11-16 10:45:05 +0000
Processing by Dashboard::TodosController#index as HTML
Completed 500 Internal Server Error in 157ms (ActiveRecord: 22.5ms)
ActionView::Template::Error (undefined method `to_reference' for nil:NilClass):
1: %li{ class: "todo todo-#{todo.done? ? 'done' : 'pending'}", id: dom_id(todo), data: { url: todo_target_path(todo) } }
2: .todo-avatar
3: = author_avatar(todo, size: 40)
4:
app/models/issue.rb:170:in `to_reference'
lib/gitlab/metrics/instrumentation.rb:159:in `block in to_reference'
lib/gitlab/metrics/method_call.rb:34:in `measure'
lib/gitlab/metrics/instrumentation.rb:159:in `to_reference'
app/models/concerns/referable.rb:37:in `referable_inspect'
config/application.rb:225:in `block (4 levels) in <class:Application>'
app/helpers/gitlab_routing_helper.rb:33:in `issue_path'
app/helpers/todos_helper.rb:52:in `todo_target_path'
app/views/dashboard/todos/_todo.html.haml:1:in `_app_views_dashboard_todos__todo_html_haml__3885649395164526844_70022898720100'
app/views/dashboard/todos/index.html.haml:87:in `_app_views_dashboard_todos_index_html_haml___2885931796454597091_70022893293940'
app/controllers/application_controller.rb:114:in `render'
lib/gitlab/i18n.rb:53:in `with_locale'
lib/gitlab/i18n.rb:59:in `with_user_locale'
app/controllers/application_controller.rb:424:in `set_locale'
lib/gitlab/middleware/multipart.rb:101:in `call'
lib/gitlab/request_profiler/middleware.rb:14:in `call'
lib/gitlab/middleware/go.rb:17:in `call'
lib/gitlab/etag_caching/middleware.rb:11:in `call'
lib/gitlab/middleware/rails_queue_duration.rb:22:in `call'
lib/gitlab/metrics/rack_middleware.rb:15:in `block in call'
lib/gitlab/metrics/transaction.rb:53:in `run'
lib/gitlab/metrics/rack_middleware.rb:15:in `call'
lib/gitlab/middleware/read_only/controller.rb:38:in `call'
lib/gitlab/middleware/read_only.rb:16:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:18:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'
lib/gitlab/middleware/release_env.rb:10:in `call'
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
root@gitlab:/# gitlab-rake gitlab:env:info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.4.5p335
Gem Version: 2.7.6
Bundler Version:1.16.2
Rake Version: 12.3.1
Redis Version: 3.2.12
Git Version: 2.18.1
Sidekiq Version:5.2.1
Go Version: unknown
GitLab information
Version: 11.4.5
Revision: f5536c6
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: https://[XXXEDITEDXXX]/apps/gitlab
HTTP Clone URL: https://[XXXEDITEDXXX]/apps/gitlab/some-group/some-project.git
SSH Clone URL: git@[XXXEDITEDXXX]:some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers: saml
GitLab Shell
Version: 8.3.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
root@gitlab:/# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...
GitLab Shell version >= 8.3.3 ? ... OK (8.3.3)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
28/2 ... ok
11/4 ... repository is empty
16/5 ... repository is empty
16/8 ... ok
77/9 ... repository is empty
15/10 ... repository is empty
15/11 ... repository is empty
15/12 ... repository is empty
33/15 ... ok
33/19 ... ok
15/20 ... repository is empty
36/21 ... repository is empty
36/22 ... repository is empty
15/23 ... repository is empty
16/24 ... repository is empty
9/25 ... repository is empty
16/26 ... repository is empty
68/32 ... repository is empty
79/34 ... repository is empty
80/35 ... repository is empty
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 Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
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: ...
28/2 ... yes
11/4 ... yes
16/5 ... yes
16/8 ... yes
77/9 ... yes
15/10 ... yes
15/11 ... yes
15/12 ... yes
33/15 ... yes
33/19 ... yes
15/20 ... yes
36/21 ... yes
36/22 ... yes
15/23 ... yes
16/24 ... yes
9/25 ... yes
16/26 ... yes
68/32 ... yes
79/34 ... yes
80/35 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.4.5)
Git version >= 2.9.5 ? ... yes (2.18.1)
Git user has default SSH configuration? ... yes
Active users: ... 15
Checking GitLab ... Finished
Possible fixes
Ensuring that Todos get deleted when a project is removed seems to solve the issue. This can be achieved with this update of the database:
alter table todos add constraint custom_project_id FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE;