Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b6f43fc9
Commit
b6f43fc9
authored
Jan 26, 2022
by
Matt Kasa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of ActiveRecord::Base in CurrentSettings
Relates to
https://gitlab.com/gitlab-org/gitlab/-/issues/350651
parent
32a93d55
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
10 deletions
+8
-10
.rubocop_todo/database/multiple_databases.yml
.rubocop_todo/database/multiple_databases.yml
+0
-2
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+2
-2
spec/lib/gitlab/current_settings_spec.rb
spec/lib/gitlab/current_settings_spec.rb
+6
-6
No files found.
.rubocop_todo/database/multiple_databases.yml
View file @
b6f43fc9
...
@@ -11,7 +11,6 @@ Database/MultipleDatabases:
...
@@ -11,7 +11,6 @@ Database/MultipleDatabases:
-
ee/spec/services/ee/merge_requests/update_service_spec.rb
-
ee/spec/services/ee/merge_requests/update_service_spec.rb
-
lib/backup/database.rb
-
lib/backup/database.rb
-
lib/backup/manager.rb
-
lib/backup/manager.rb
-
lib/gitlab/current_settings.rb
-
lib/gitlab/database/load_balancing/load_balancer.rb
-
lib/gitlab/database/load_balancing/load_balancer.rb
-
lib/gitlab/database/load_balancing.rb
-
lib/gitlab/database/load_balancing.rb
-
lib/gitlab/database/load_balancing/sticking.rb
-
lib/gitlab/database/load_balancing/sticking.rb
...
@@ -29,7 +28,6 @@ Database/MultipleDatabases:
...
@@ -29,7 +28,6 @@ Database/MultipleDatabases:
-
spec/db/schema_spec.rb
-
spec/db/schema_spec.rb
-
spec/initializers/database_config_spec.rb
-
spec/initializers/database_config_spec.rb
-
spec/lib/backup/manager_spec.rb
-
spec/lib/backup/manager_spec.rb
-
spec/lib/gitlab/current_settings_spec.rb
-
spec/lib/gitlab/database_spec.rb
-
spec/lib/gitlab/database_spec.rb
-
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
-
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
-
spec/lib/gitlab/profiler_spec.rb
-
spec/lib/gitlab/profiler_spec.rb
...
...
lib/gitlab/current_settings.rb
View file @
b6f43fc9
...
@@ -62,7 +62,7 @@ module Gitlab
...
@@ -62,7 +62,7 @@ module Gitlab
# need to be added to the application settings. To prevent Rake tasks
# need to be added to the application settings. To prevent Rake tasks
# and other callers from failing, use any loaded settings and return
# and other callers from failing, use any loaded settings and return
# defaults for missing columns.
# defaults for missing columns.
if
Gitlab
::
Runtime
.
rake?
&&
ActiveRecord
::
Base
.
connection
.
migration_context
.
needs_migration?
if
Gitlab
::
Runtime
.
rake?
&&
::
ApplicationSetting
.
connection
.
migration_context
.
needs_migration?
db_attributes
=
current_settings
&
.
attributes
||
{}
db_attributes
=
current_settings
&
.
attributes
||
{}
fake_application_settings
(
db_attributes
)
fake_application_settings
(
db_attributes
)
elsif
current_settings
.
present?
elsif
current_settings
.
present?
...
@@ -82,7 +82,7 @@ module Gitlab
...
@@ -82,7 +82,7 @@ module Gitlab
def
connect_to_db?
def
connect_to_db?
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
active_db_connection
=
ActiveRecord
::
Base
.
connection
.
active?
rescue
false
active_db_connection
=
::
ApplicationSetting
.
connection
.
active?
rescue
false
active_db_connection
&&
active_db_connection
&&
ApplicationSetting
.
database
.
cached_table_exists?
ApplicationSetting
.
database
.
cached_table_exists?
...
...
spec/lib/gitlab/current_settings_spec.rb
View file @
b6f43fc9
...
@@ -118,7 +118,7 @@ RSpec.describe Gitlab::CurrentSettings do
...
@@ -118,7 +118,7 @@ RSpec.describe Gitlab::CurrentSettings do
allow
(
Gitlab
::
Runtime
).
to
receive
(
:rake?
).
and_return
(
true
)
allow
(
Gitlab
::
Runtime
).
to
receive
(
:rake?
).
and_return
(
true
)
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(false)` causes issues
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(false)` causes issues
# during the initialization phase of the test suite, so instead let's mock the internals of it
# during the initialization phase of the test suite, so instead let's mock the internals of it
allow
(
A
ctiveRecord
::
Base
.
connection
).
to
receive
(
:active?
).
and_return
(
false
)
allow
(
A
pplicationSetting
.
connection
).
to
receive
(
:active?
).
and_return
(
false
)
end
end
context
'and no settings in cache'
do
context
'and no settings in cache'
do
...
@@ -150,8 +150,8 @@ RSpec.describe Gitlab::CurrentSettings do
...
@@ -150,8 +150,8 @@ RSpec.describe Gitlab::CurrentSettings do
it
'fetches the settings from cache'
do
it
'fetches the settings from cache'
do
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(true)` causes issues
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(true)` causes issues
# during the initialization phase of the test suite, so instead let's mock the internals of it
# during the initialization phase of the test suite, so instead let's mock the internals of it
expect
(
A
ctiveRecord
::
Base
.
connection
).
not_to
receive
(
:active?
)
expect
(
A
pplicationSetting
.
connection
).
not_to
receive
(
:active?
)
expect
(
A
ctiveRecord
::
Base
.
connection
).
not_to
receive
(
:cached_table_exists?
)
expect
(
A
pplicationSetting
.
connection
).
not_to
receive
(
:cached_table_exists?
)
expect_any_instance_of
(
ActiveRecord
::
MigrationContext
).
not_to
receive
(
:needs_migration?
)
expect_any_instance_of
(
ActiveRecord
::
MigrationContext
).
not_to
receive
(
:needs_migration?
)
expect
(
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
current_application_settings
}.
count
).
to
eq
(
0
)
expect
(
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
current_application_settings
}.
count
).
to
eq
(
0
)
end
end
...
@@ -159,8 +159,8 @@ RSpec.describe Gitlab::CurrentSettings do
...
@@ -159,8 +159,8 @@ RSpec.describe Gitlab::CurrentSettings do
context
'and no settings in cache'
do
context
'and no settings in cache'
do
before
do
before
do
allow
(
A
ctiveRecord
::
Base
.
connection
).
to
receive
(
:active?
).
and_return
(
true
)
allow
(
A
pplicationSetting
.
connection
).
to
receive
(
:active?
).
and_return
(
true
)
allow
(
A
ctiveRecord
::
Base
.
connection
).
to
receive
(
:cached_table_exists?
).
with
(
'application_settings'
).
and_return
(
true
)
allow
(
A
pplicationSetting
.
connection
).
to
receive
(
:cached_table_exists?
).
with
(
'application_settings'
).
and_return
(
true
)
end
end
context
'with RequestStore enabled'
,
:request_store
do
context
'with RequestStore enabled'
,
:request_store
do
...
@@ -181,7 +181,7 @@ RSpec.describe Gitlab::CurrentSettings do
...
@@ -181,7 +181,7 @@ RSpec.describe Gitlab::CurrentSettings do
context
'when ApplicationSettings does not have a primary key'
do
context
'when ApplicationSettings does not have a primary key'
do
before
do
before
do
allow
(
A
ctiveRecord
::
Base
.
connection
).
to
receive
(
:primary_key
).
with
(
'application_settings'
).
and_return
(
nil
)
allow
(
A
pplicationSetting
.
connection
).
to
receive
(
:primary_key
).
with
(
'application_settings'
).
and_return
(
nil
)
end
end
it
'raises an exception if ApplicationSettings does not have a primary key'
do
it
'raises an exception if ApplicationSettings does not have a primary key'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment