Skip to content

Fix project's full_name erroring out

Thong Kuah requested to merge fix_full_name_erroring into master

What does this MR do and why?

Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/424213

It seems at some point the user was deleted, but the user namespace still remained, along with projects under that user namespace.

There is a need in https://gitlab.com/gitlab-org/gitlab/-/issues/424213 to access the project via v4 API, so this MR fixes errors resulting from a missing owner

  1. Fix project's full_name erroring out

Some old projects have full_name erroring because their user namespace has a missing owner. The full_name consists of the user namespace's human_name + the project's name.

So we return path if for any reason, the owner_name is nil.

  1. Fix NamespaceBasic serialization for namespace with missing owner

There are some user namespaces where the owner is missing for some reason. This is causing error when showing projects via the API. We fix this by using the route path which still exist.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Run bundle exec rspec spec/requests/api/projects_spec.rb -e 'with user namespace that has a missing owner'

On master, this fails with:

caught error of type NoMethodError in after callback inside Grape::Middleware::Formatter : undefined method `+' for nil:NilClass

      parent.human_name + ' / ' + name
                        ^
F

Failures:

  1) API::Projects GET /projects when authenticated as regular user includes various project feature fields
     Failure/Error: project_response = json_response.find { |p| p['id'] == project.id }
     
     TypeError:
       no implicit conversion of String into Integer
     # ./spec/requests/api/projects_spec.rb:230:in `block (5 levels) in <top (required)>'
     # ./spec/requests/api/projects_spec.rb:230:in `each'
     # ./spec/requests/api/projects_spec.rb:230:in `find'
     # ./spec/requests/api/projects_spec.rb:230:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:445:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:18:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:436:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:432:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:66:in `with_raw_context'
     # ./spec/spec_helper.rb:432:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:272:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

Finished in 10.68 seconds (files took 11.05 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/api/projects_spec.rb:226 # API::Projects GET /projects when authenticated as regular user includes various project feature fields

[TEST PROF INFO] Time spent in factories: 00:02.269 (17.38% of total time)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thong Kuah

Merge request reports

Loading