Skip to content

Replace default_value_for on User models - second try

Marius Bobin requested to merge revert-3d58dce9 into master

What does this MR do and why?

It brings back the changes reverted by !104445 (merged) and fixes the state machine so that it doesn't evaluate the default attributes on class load.

How to set up and validate locally

Change the attributes definitions to raise errors:

diff --git a/app/models/user.rb b/app/models/user.rb
index b73f2b268d7c..6a846fc32baa 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -59,15 +59,15 @@ class User < ApplicationRecord
   add_authentication_token_field :static_object_token, encrypted: :optional
 
   attribute :admin, default: false
-  attribute :external, default: -> { Gitlab::CurrentSettings.user_default_external }
-  attribute :can_create_group, default: -> { Gitlab::CurrentSettings.can_create_group }
+  attribute :external, default: -> { 1/0; Gitlab::CurrentSettings.user_default_external }
+  attribute :can_create_group, default: -> { 1/0; Gitlab::CurrentSettings.can_create_group }
   attribute :can_create_team, default: false
   attribute :hide_no_ssh_key, default: false
   attribute :hide_no_password, default: false
   attribute :project_view, default: :files
   attribute :notified_of_own_activity, default: false
-  attribute :preferred_language, default: -> { I18n.default_locale }
-  attribute :theme_id, default: -> { gitlab_config.default_theme }
+  attribute :preferred_language, default: -> { 1/0; I18n.default_locale }
+  attribute :theme_id, default: -> { 1/0; gitlab_config.default_theme }
 
   attr_encrypted :otp_secret,
     key: Gitlab::Application.secrets.otp_key_base,

Interact with the User model:

bin/rails runner "puts User.last.id"

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 Marius Bobin

Merge request reports

Loading