Unable to save project. Error: undefined method `any?' for nil:NilClass\n\n

Problem to solve

After creating a subgroup via the API, any project created with that subgroup defined results in 500 errors on the site.

Steps to reproduce

curl -XPOST https://our.internal.gitlab/api/v4/groups -H'PRIVATE-TOKEN:TOKEN' -H'Content-Type: application/json' -d '{"name":"coolguys","path":"coolguys", "parent_id":"123","description":"subgroup to 123","visibility":"private","default_branch_protection_defaults":{"allow_force_push":true}}'
curl -XPOST https://our.internal.gitlab/api/v4/projects -H'PRIVATE-TOKEN: TOKEN' -H'Content-Type: application/json' -d '{"name":"coolproject","initialize_with_readme":true,"namespace_id":"124","description":"bleh","visibility":"private"}'
gitlab-ctl tail gitlab-rails

`block in handle_request'","puma (6.4.0) lib/puma/thread_pool.rb:378:in `with_force_shutdown'","puma (6.4.0) lib/puma/request.rb:99:in `handle_request'","puma (6.4.0) lib/puma/server.rb:443:in `process_client'","puma (6.4.0) lib/puma/server.rb:241:in `block in run'","puma (6.4.0) lib/puma/thread_pool.rb:155:in `block in spawn_thread'"],"exception.cause_class":"NoMethodError","db_duration_s":0.02953,"view_duration_s":0.0,"duration_s":0.23892}

==> /var/log/gitlab/gitlab-rails/production.log <==

ActionView::Template::Error (undefined method `any?' for nil:NilClass

        allowed_to_push_values.any? { |entry| entry[:access_level] == Gitlab::Access::DEVELOPER }
                              ^^^^^):
    50:                 touch README.md
    51:                 git add README.md
    52:                 git commit -m "add README"
    53:               - if @project.can_current_user_push_to_default_branch?
    54:                 %span><
    55:                   git push --set-upstream origin #{h escaped_default_branch_name }
    56:

lib/gitlab/access/default_branch_protection.rb:59:in `developer_can_push?'
app/models/project.rb:2993:in `default_branch_protected?'
app/models/protected_branch.rb:46:in `protected?'
lib/gitlab/user_access.rb:140:in `protected?'

The project is visible in the Web UI but clicking it results in:

500: We’re sorry, something went wrong on our end

Request ID: blahblahblah

Try refreshing the page, or going back and attempting the action again.

Please contact your GitLab administrator if this problem persists.

Grep’ing this Request ID in /var/log/gitlab shows the same error about undefined method `any?’ for nil:NilClass in /var/log/gitlab/gitlab-rails/production_json.log

"worker_id":"puma_5","rate_limiting_gates":[],"exception.class":"ActionView::Template::Error","exception.message":"undefined method `any?' for nil:NilClass\n\n        allowed_to_push_values.any? { |entry| entry[:access_level] == Gitlab::Access::DEVELOPER }\n                              ^^^^^","exception.backtrace":["lib/gitlab/access/default_branch_protection.rb:59:in `developer_can_push?'","app/models/project.rb:2993:in `default_branch_protected?'","app/models/protected_branch.rb:46:in `protected?'","lib/gitlab/user_access.rb:140:in `protected?'","lib/gitlab/cache/request_cache.rb:43:in `block (3 levels) in request_cache'","request_store (1.5.1) lib/request_store.rb:51:in `fetch'","lib/gitlab/cache/request_cache.rb:43:in `block (2 levels) in request_cache'","lib/gitlab/user_access.rb:70:in `can_push_to_branch?'","lib/gitlab/cache/request_cache.rb:43:in `block (3 levels) in request_cache'","request_store (1.5.1) lib/request_store.rb:51:in `fetch'","lib/gitlab/cache/request_cache.rb:43:in `block (2 levels) in request_cache'","app/presenters/project_presenter.rb:164:in `can_current_user_push_to_branch?'","app/presenters/project_presenter.rb:168:in `can_current_user_push_to_default_branch?'","app/views/projects/empty.html.haml:53","actionview (7.0.8.4) lib/action_view/helpers/capture_helper.rb:45:in `block in capture'","actionview (7.0.8.4) lib/action_view/helpers/capture_helper.rb:209:in `with_output_buffer'","actionview (7.0.8.4) lib/action_view/he

Versions

Please select whether options apply, and add the version information.

Versions

  • gitlab-ce 17.3.0-ce.0
System information
System:		Debian 12
Current User:	git
Using RVM:	no
Ruby Version:	3.1.5p253
Gem Version:	3.5.11
Bundler Version:2.5.11
Rake Version:	13.0.6
Redis Version:	7.0.15
Sidekiq Version:7.1.6
Go Version:	unknown

GitLab information
Version:	17.3.0
Revision:	95e5ead83ae
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	PostgreSQL
DB Version:	14.11
URL:		https://redacted-fqdn
HTTP Clone URL:	https://redacted-fqdn/some-group/some-project.git
SSH Clone URL:	git@redacted-fqdn:some-group/some-project.git
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers:

GitLab Shell
Version:	14.38.0
Repository storages:
- default: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path:		/opt/gitlab/embedded/service/gitlab-shell

Gitaly
- default Address: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 	17.3.0
- default Git Version: 	2.45.2

Also running db:migrate:status returns “up” for all migrations.

It looks like you are experiencing a known issue. There are currently two available workarounds.