500 response on GET custom attributes if project is not found
Summary
If a project is deleted, GET to /api/v4/projects/:id/custom_attributes returns 500
Steps to reproduce
- use admin token to send a GET request to
/api/v4/projects/:id/custom_attributeswith an invalid id
Example Project
What is the current bug behavior?
What is the expected correct behavior?
Relevant logs and/or screenshots
"route":"/api/:version/groups/:id/custom_attributes",
"exception.class":"NoMethodError","exception.message":"undefined method
`custom_attributes' for nil:NilClass",
"exception.backtrace":["lib/api/custom_attributes_endpoints.rb:26:
in `block (2 levels) in <module:CustomAttributesEndpoints>'","lib/api/api_guard.rb:213:
in `call'","lib/gitlab/middleware/speedscope.rb:13:in `call'","lib/gitlab/request_profiler/middleware.rb:17:in `call'","lib/gitlab/jira/middleware.rb:19:
in `call'","lib/gitlab/middleware/go.rb:20:in
Output of checks
Results of GitLab environment info
self hosted gitlab-ce v14.0.8
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)
Possible fixes
https://gitlab.com/yuanchenlu/gitlab-rails/-/merge_requests/1/diffs
Edited by Yuanchen Lu