Skip to content

Commit 278ebf5

Browse files
committed
Fix ActiveRecord::Base.inspect to correctly indicate how to load schema
Fix: rails#52601 Now that Active Record connections are fully lazy, just calling `.lease_connection` isn't actually enough to estalish a connection. We might as well suggest to use a method with the actual intent.
1 parent 7c8704a commit 278ebf5

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

activerecord/lib/active_record/core.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def inspect # :nodoc:
354354
super
355355
elsif abstract_class?
356356
"#{super}(abstract)"
357-
elsif !connected?
358-
"#{super} (call '#{super}.lease_connection' to establish a connection)"
357+
elsif !schema_loaded? && !connected?
358+
"#{super} (call '#{super}.load_schema' to load schema informations)"
359359
elsif table_exists?
360360
attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", "
361361
"#{super}(#{attr_list})"

activerecord/lib/active_record/encryption/encryptable_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def override_accessors_to_preserve_original(name, original_attribute_name)
123123
end)
124124
end
125125

126-
def load_schema!
126+
def load_schema! # :nodoc:
127127
super
128128

129129
add_length_validation_for_encrypted_columns if ActiveRecord::Encryption.config.validate_column_size

activerecord/lib/active_record/model_schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ def reset_column_information
531531
initialize_find_by_cache
532532
end
533533

534-
def load_schema # :nodoc:
534+
# Load the model's schema information either from the schema cache
535+
# or directly from the database.
536+
def load_schema
535537
return if schema_loaded?
536538
@load_schema_monitor.synchronize do
537539
return if schema_loaded?

activerecord/test/cases/invalid_connection_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setup
2020
end
2121

2222
test "inspect on Model class does not raise" do
23-
assert_equal "#{Bird.name} (call '#{Bird.name}.lease_connection' to establish a connection)", Bird.inspect
23+
assert_equal "#{Bird.name} (call '#{Bird.name}.load_schema' to load schema informations)", Bird.inspect
2424
end
2525
end
2626
end

0 commit comments

Comments
 (0)