Skip to content

Commit 25c4574

Browse files
authored
Merge pull request rails#51146 from rails/rm-deprecations-2
Remove all deprecated code from Active Record
2 parents 052b5ed + eccc606 commit 25c4574

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+357
-988
lines changed

activerecord/CHANGELOG.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,130 @@
1+
* Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
2+
3+
*Rafael Mendonça França*
4+
5+
* Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
6+
7+
*Rafael Mendonça França*
8+
9+
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
10+
11+
*Rafael Mendonça França*
12+
13+
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
14+
15+
*Rafael Mendonça França*
16+
17+
* Remove deprecated support to quote `ActiveSupport::Duration`.
18+
19+
*Rafael Mendonça França*
20+
21+
* Remove deprecated `#quote_bound_value`.
22+
23+
*Rafael Mendonça França*
24+
25+
* Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
26+
27+
*Rafael Mendonça França*
28+
29+
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
30+
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
31+
for the current role when the `role` argument isn't provided.
32+
33+
*Rafael Mendonça França*
34+
35+
* Remove deprecated `#all_connection_pools`.
36+
37+
*Rafael Mendonça França*
38+
39+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
40+
41+
*Rafael Mendonça França*
42+
43+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
44+
45+
*Rafael Mendonça França*
46+
47+
* Remove deprecated `#all_foreign_keys_valid?` from database adapters.
48+
49+
*Rafael Mendonça França*
50+
51+
* Remove deprecated support to passing coder and class as second argument to `serialize`.
52+
53+
*Rafael Mendonça França*
54+
55+
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
56+
57+
*Rafael Mendonça França*
58+
59+
* Remove deprecated `TestFixtures.fixture_path`.
60+
61+
*Rafael Mendonça França*
62+
63+
* Remove deprecated behavior to support referring to a singular association by its plural name.
64+
65+
*Rafael Mendonça França*
66+
67+
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`
68+
69+
*Rafael Mendonça França*
70+
71+
* Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
72+
`ActiveRecord::MigrationContext`.
73+
74+
*Rafael Mendonça França*
75+
76+
* Remove deprecated `ActiveRecord::Migration.check_pending` method.
77+
78+
*Rafael Mendonça França*
79+
80+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
81+
82+
*Rafael Mendonça França*
83+
84+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
85+
86+
*Rafael Mendonça França*
87+
88+
* Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
89+
90+
*Rafael Mendonça França*
91+
92+
* Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
93+
94+
*Rafael Mendonça França*
95+
96+
* Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
97+
98+
*Rafael Mendonça França*
99+
100+
* Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
101+
102+
*Rafael Mendonça França*
103+
104+
* Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
105+
106+
*Rafael Mendonça França*
107+
108+
* Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
109+
110+
*Rafael Mendonça França*
111+
112+
* Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
113+
114+
*Rafael Mendonça França*
115+
116+
* Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
117+
118+
*Rafael Mendonça França*
119+
120+
* Remove deprecated support to call `alias_attribute` with non-existent attribute names.
121+
122+
*Rafael Mendonça França*
123+
124+
* Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
125+
126+
*Rafael Mendonça França*
127+
1128
* Add ActiveRecord::Encryption::MessagePackMessageSerializer
2129

3130
Serialize data to the MessagePack format, for efficient storage in binary columns.

activerecord/lib/active_record.rb

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,19 @@ def self.global_executor_concurrency # :nodoc:
333333
singleton_class.attr_accessor :run_after_transaction_callbacks_in_order_defined
334334
self.run_after_transaction_callbacks_in_order_defined = false
335335

336-
singleton_class.attr_accessor :commit_transaction_on_non_local_return
337-
self.commit_transaction_on_non_local_return = false
336+
def self.commit_transaction_on_non_local_return
337+
ActiveRecord.deprecator.warn <<-WARNING.squish
338+
`Rails.application.config.active_record.commit_transaction_on_non_local_return`
339+
is deprecated and will be removed in Rails 7.3.
340+
WARNING
341+
end
342+
343+
def self.commit_transaction_on_non_local_return=(value)
344+
ActiveRecord.deprecator.warn <<-WARNING.squish
345+
`Rails.application.config.active_record.commit_transaction_on_non_local_return`
346+
is deprecated and will be removed in Rails 7.3.
347+
WARNING
348+
end
338349

339350
##
340351
# :singleton-method: warn_on_records_fetched_greater_than
@@ -413,20 +424,6 @@ def self.global_executor_concurrency # :nodoc:
413424
singleton_class.attr_accessor :dump_schemas
414425
self.dump_schemas = :schema_search_path
415426

416-
def self.suppress_multiple_database_warning
417-
ActiveRecord.deprecator.warn(<<-MSG.squish)
418-
config.active_record.suppress_multiple_database_warning is deprecated and will be removed in Rails 7.2.
419-
It no longer has any effect and should be removed from the configuration file.
420-
MSG
421-
end
422-
423-
def self.suppress_multiple_database_warning=(value)
424-
ActiveRecord.deprecator.warn(<<-MSG.squish)
425-
config.active_record.suppress_multiple_database_warning= is deprecated and will be removed in Rails 7.2.
426-
It no longer has any effect and should be removed from the configuration file.
427-
MSG
428-
end
429-
430427
##
431428
# :singleton-method: verify_foreign_keys_for_fixtures
432429
# If true, Rails will verify all foreign keys in the database after loading fixtures.
@@ -436,12 +433,19 @@ def self.suppress_multiple_database_warning=(value)
436433
singleton_class.attr_accessor :verify_foreign_keys_for_fixtures
437434
self.verify_foreign_keys_for_fixtures = false
438435

439-
##
440-
# :singleton-method: allow_deprecated_singular_associations_name
441-
# If true, Rails will continue allowing plural association names in where clauses on singular associations
442-
# This behavior will be removed in Rails 7.2.
443-
singleton_class.attr_accessor :allow_deprecated_singular_associations_name
444-
self.allow_deprecated_singular_associations_name = true
436+
def self.allow_deprecated_singular_associations_name
437+
ActiveRecord.deprecator.warn <<-WARNING.squish
438+
`Rails.application.config.active_record.allow_deprecated_singular_associations_name`
439+
is deprecated and will be removed in Rails 7.3.
440+
WARNING
441+
end
442+
443+
def self.allow_deprecated_singular_associations_name=(value)
444+
ActiveRecord.deprecator.warn <<-WARNING.squish
445+
`Rails.application.config.active_record.allow_deprecated_singular_associations_name`
446+
is deprecated and will be removed in Rails 7.3.
447+
WARNING
448+
end
445449

446450
singleton_class.attr_accessor :query_transformers
447451
self.query_transformers = []

activerecord/lib/active_record/attribute_methods.rb

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,15 @@ def eagerly_generate_alias_attribute_methods(_new_name, _old_name) # :nodoc:
7878
end
7979

8080
def alias_attribute_method_definition(code_generator, pattern, new_name, old_name)
81-
method_name = pattern.method_name(new_name).to_s
82-
target_name = pattern.method_name(old_name).to_s
83-
parameters = pattern.parameters
8481
old_name = old_name.to_s
8582

86-
method_defined = method_defined?(target_name) || private_method_defined?(target_name)
87-
manually_defined = method_defined &&
88-
!self.instance_method(target_name).owner.is_a?(GeneratedAttributeMethods)
89-
reserved_method_name = ::ActiveRecord::AttributeMethods.dangerous_attribute_methods.include?(target_name)
90-
9183
if !abstract_class? && !has_attribute?(old_name)
92-
# We only need to issue this deprecation warning once, so we issue it when defining the original reader method.
93-
should_warn = target_name == old_name
94-
if should_warn
95-
ActiveRecord.deprecator.warn(
96-
"#{self} model aliases `#{old_name}`, but `#{old_name}` is not an attribute. " \
97-
"Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. " \
98-
"Use `alias_method :#{new_name}, :#{old_name}` or define the method manually."
99-
)
100-
end
101-
super
102-
elsif manually_defined && !reserved_method_name
103-
aliased_method_redefined_as_well = method_defined_within?(method_name, self)
104-
return if aliased_method_redefined_as_well
105-
106-
ActiveRecord.deprecator.warn(
107-
"#{self} model aliases `#{old_name}` and has a method called `#{target_name}` defined. " \
108-
"Starting in Rails 7.2 `#{method_name}` will not be calling `#{target_name}` anymore. " \
109-
"You may want to additionally define `#{method_name}` to preserve the current behavior."
110-
)
111-
super
84+
raise ArgumentError, "#{self.name} model aliases `#{old_name}`, but `#{old_name}` is not an attribute. " \
85+
"Use `alias_method :#{new_name}, :#{old_name}` or define the method manually."
11286
else
87+
method_name = pattern.method_name(new_name).to_s
88+
parameters = pattern.parameters
89+
11390
define_proxy_call(code_generator, method_name, pattern.proxy_target, parameters, old_name,
11491
namespace: :proxy_alias_attribute
11592
)

activerecord/lib/active_record/attribute_methods/read.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,7 @@ def read_attribute(attr_name, &block)
3030
name = attr_name.to_s
3131
name = self.class.attribute_aliases[name] || name
3232

33-
return @attributes.fetch_value(name, &block) unless name == "id" && @primary_key
34-
35-
if self.class.composite_primary_key?
36-
@attributes.fetch_value("id", &block)
37-
else
38-
if @primary_key != "id"
39-
ActiveRecord.deprecator.warn(<<-MSG.squish)
40-
Using read_attribute(:id) to read the primary key value is deprecated.
41-
Use #id instead.
42-
MSG
43-
end
44-
@attributes.fetch_value(@primary_key, &block)
45-
end
33+
@attributes.fetch_value(name, &block)
4634
end
4735

4836
# This method exists to avoid the expensive primary_key check internally, without

activerecord/lib/active_record/attribute_methods/serialization.rb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,7 @@ module ClassMethods
180180
# serialize :preferences, coder: Rot13JSON
181181
# end
182182
#
183-
def serialize(attr_name, class_name_or_coder = nil, coder: nil, type: Object, yaml: {}, **options)
184-
unless class_name_or_coder.nil?
185-
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
186-
ActiveRecord.deprecator.warn(<<~MSG)
187-
Passing the coder as positional argument is deprecated and will be removed in Rails 7.2.
188-
189-
Please pass the coder as a keyword argument:
190-
191-
serialize #{attr_name.inspect}, coder: #{class_name_or_coder}
192-
MSG
193-
coder = class_name_or_coder
194-
else
195-
ActiveRecord.deprecator.warn(<<~MSG)
196-
Passing the class as positional argument is deprecated and will be removed in Rails 7.2.
197-
198-
Please pass the class as a keyword argument:
199-
200-
serialize #{attr_name.inspect}, type: #{class_name_or_coder.name}
201-
MSG
202-
type = class_name_or_coder
203-
end
204-
end
205-
183+
def serialize(attr_name, coder: nil, type: Object, yaml: {}, **options)
206184
coder ||= default_column_serializer
207185
unless coder
208186
raise ArgumentError, <<~MSG.squish

0 commit comments

Comments
 (0)