Gitlab-rails create new user - Validation failed: Namespace can't be blank (ActiveRecord::RecordInvalid) Issue

Hello, gitlab rails started giving this error for a reason we don’t know. In the past, we were creating new users using this script.

system information:
gitlab package:

gitlab-ce

OS:

Debian 12 bookworm

“gitlab-rake gitlab:env:info” :

System information
System:		Debian 12
Current User:	git
Using RVM:	no
Ruby Version:	3.1.4p223
Gem Version:	3.4.22
Bundler Version:2.5.4
Rake Version:	13.0.6
Redis Version:	7.0.15
Sidekiq Version:7.1.6
Go Version:	unknown

GitLab information
Version:	16.8.1
Revision:	a658d811568
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	PostgreSQL
DB Version:	15.5
URL:		https://gitlab.example.org
HTTP Clone URL:	https://gitlab.example.org/some-group/some-project.git
SSH Clone URL:	git@gitlab.example.org:some-group/some-project.git
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers: 

GitLab Shell
Version:	14.33.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: 	16.8.1
- default Git Version: 	2.42.0

user create script: create-accounts.sh

nohup gitlab-rails runner "u = User.new(username: '$1', email: '$2', name: '$3 $4', password: '$5', password_confirmation: '$5'); u.skip_confirmation!; u.save!"

Error:

./create-accounts.sh ‘test’ ‘test@test.com’ ‘firstname_test’ ‘lastname_test’ ‘:cppYR3xg.3asdfas’

Output:

/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/validations.rb:80:in `raise_validation_error': Validation failed: Namespace can't be blank (ActiveRecord::RecordInvalid)
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/validations.rb:53:in `save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:302:in `block in save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `public_send'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `block in write_using_load_balancer'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:141:in `block in read_write'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:228:in `retry_with_backoff'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:130:in `read_write'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `write_using_load_balancer'
	from /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:78:in `transaction'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:302:in `save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/suppressor.rb:54:in `save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-activerecord-0.8.0/lib/state_machines/integrations/active_record.rb:515:in `block in save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-activerecord-0.8.0/lib/state_machines/integrations/active_record.rb:530:in `block in around_save'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:150:in `block in run_actions'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:170:in `catch_exceptions'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:148:in `run_actions'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:133:in `run_callbacks'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:212:in `run_callbacks'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:63:in `block (2 levels) in perform'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:63:in `catch'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:63:in `block in perform'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:186:in `within_transaction'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-0.5.0/lib/state_machines/transition_collection.rb:62:in `perform'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-activerecord-0.8.0/lib/state_machines/integrations/active_record.rb:530:in `around_save'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/state_machines-activerecord-0.8.0/lib/state_machines/integrations/active_record.rb:515:in `save!'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/commands/runner/runner_command.rb:46:in `<main>'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/commands/runner/runner_command.rb:46:in `eval'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/commands/runner/runner_command.rb:46:in `perform'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/command/base.rb:87:in `perform'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/command.rb:48:in `invoke'
	from /opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/commands.rb:18:in `<top (required)>'
	from <internal:/opt/gitlab/embedded/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
	from <internal:/opt/gitlab/embedded/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
	from bin/rails:4:in `<main>'

Hi,

There was a recent change in creating a user. The user must be assigned to a user namespace. I have created MR to update the documentation

u = User.new(username: 'tesst', email: 'example@example.com', name: 'test user', password: 'test_user_pass', password_confirmation: 'test_user_pass')
u.assign_personal_namespace
u.skip_confirmation! # Use it only if you wish user to be automatically confirmed. If skipped, user receives confirmation e-mail
u.save!
1 Like

Thank you for your help and contribution to the community <3