Skip to content

Commit 2a761d2

Browse files
committed
Remove deprecated primitive serializer for BigDecimal arguments
1 parent ec2c266 commit 2a761d2

File tree

8 files changed

+23
-97
lines changed

8 files changed

+23
-97
lines changed

activejob/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
* Deprecate `Rails.application.config.active_job.use_big_decimal_serialize`.
2+
3+
*Rafael Mendonça França*
4+
5+
* Remove deprecated primitive serializer for `BigDecimal` arguments.
6+
7+
*Rafael Mendonça França*
18

29
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activejob/CHANGELOG.md) for previous changes.

activejob/lib/active_job.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ module ActiveJob
4545
autoload :TestCase
4646
autoload :TestHelper
4747

48-
##
49-
# :singleton-method:
50-
# If false, \Rails will preserve the legacy serialization of BigDecimal job arguments as Strings.
51-
# If true, \Rails will use the new BigDecimalSerializer to (de)serialize BigDecimal losslessly.
52-
# Legacy serialization will be removed in \Rails 7.2, along with this config.
53-
singleton_class.attr_accessor :use_big_decimal_serializer
54-
self.use_big_decimal_serializer = false
48+
def self.use_big_decimal_serializer
49+
ActiveJob.deprecator.warn <<-WARNING.squish
50+
Rails.application.config.active_job.use_big_decimal_serializer is deprecated and will be removed in Rails 7.3.
51+
WARNING
52+
end
53+
54+
def self.use_big_decimal_serializer=(value)
55+
ActiveJob.deprecator.warn <<-WARNING.squish
56+
Rails.application.config.active_job.use_big_decimal_serializer is deprecated and will be removed in Rails 7.3.
57+
WARNING
58+
end
5559

5660
##
5761
# :singleton-method:

activejob/lib/active_job/arguments.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ def serialize_argument(argument)
101101
else
102102
if argument.respond_to?(:permitted?) && argument.respond_to?(:to_h)
103103
serialize_indifferent_hash(argument.to_h)
104-
elsif BigDecimal === argument && !ActiveJob.use_big_decimal_serializer
105-
ActiveJob.deprecator.warn(<<~MSG)
106-
Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
107-
Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
108-
109-
Note that if your application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
110-
This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
111-
MSG
112-
argument
113104
else
114105
Serializers.serialize(argument)
115106
end
@@ -120,8 +111,6 @@ def deserialize_argument(argument)
120111
case argument
121112
when nil, true, false, String, Integer, Float
122113
argument
123-
when BigDecimal # BigDecimal may have been legacy serialized; Remove in 7.2
124-
argument
125114
when Array
126115
argument.map { |arg| deserialize_argument(arg) }
127116
when Hash

activejob/test/cases/argument_serialization_test.rb

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class StringWithoutSerializer < String
5050
end
5151

5252
[ nil, 1, 1.0, 1_000_000_000_000_000_000_000,
53-
"a", true, false,
53+
"a", true, false, BigDecimal(5),
5454
:a,
5555
1.day,
5656
Date.new(2001, 2, 3),
@@ -81,28 +81,6 @@ class StringWithoutSerializer < String
8181
end
8282
end
8383

84-
test "dangerously treats BigDecimal arguments as primitives not requiring serialization by default" do
85-
assert_deprecated(<<~MSG.chomp, ActiveJob.deprecator) do
86-
Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
87-
Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
88-
89-
Note that if your application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
90-
This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
91-
MSG
92-
assert_equal(
93-
BigDecimal(5),
94-
*ActiveJob::Arguments.deserialize(ActiveJob::Arguments.serialize([BigDecimal(5)])),
95-
)
96-
end
97-
end
98-
99-
test "safely serializes BigDecimal arguments if configured to use_big_decimal_serializer" do
100-
# BigDecimal(5) example should be moved back up into array above in Rails 7.2
101-
with_big_decimal_serializer do
102-
assert_arguments_unchanged BigDecimal(5)
103-
end
104-
end
105-
10684
[ Object.new, Person.find("5").to_gid, Class.new ].each do |arg|
10785
test "does not serialize #{arg.class}" do
10886
assert_raises ActiveJob::SerializationError do
@@ -297,12 +275,4 @@ def perform_round_trip(args)
297275

298276
JobBuffer.last_value
299277
end
300-
301-
def with_big_decimal_serializer(temporary = true)
302-
original = ActiveJob.use_big_decimal_serializer
303-
ActiveJob.use_big_decimal_serializer = temporary
304-
yield
305-
ensure
306-
ActiveJob.use_big_decimal_serializer = original
307-
end
308278
end

guides/source/7_2_release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ Please refer to the [Changelog][active-job] for detailed changes.
145145

146146
### Removals
147147

148+
* Remove deprecated primitive serializer for `BigDecimal` arguments.
149+
148150
### Deprecations
149151

152+
* Deprecate `Rails.application.config.active_job.use_big_decimal_serialize`.
153+
150154
### Notable changes
151155

152156
Action Text

guides/source/configuring.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Below are the default values associated with each target version. In cases of co
6464
- [`config.action_dispatch.default_headers`](#config-action-dispatch-default-headers): `{ "X-Frame-Options" => "SAMEORIGIN", "X-XSS-Protection" => "0", "X-Content-Type-Options" => "nosniff", "X-Permitted-Cross-Domain-Policies" => "none", "Referrer-Policy" => "strict-origin-when-cross-origin" }`
6565
- [`config.action_text.sanitizer_vendor`](#config-action-text-sanitizer-vendor): `Rails::HTML::Sanitizer.best_supported_vendor`
6666
- [`config.action_view.sanitizer_vendor`](#config-action-view-sanitizer-vendor): `Rails::HTML::Sanitizer.best_supported_vendor`
67-
- [`config.active_job.use_big_decimal_serializer`](#config-active-job-use-big-decimal-serializer): `true`
6867
- [`config.active_record.allow_deprecated_singular_associations_name`](#config-active-record-allow-deprecated-singular-associations-name): `false`
6968
- [`config.active_record.before_committed_on_all_records`](#config-active-record-before-committed-on-all-records): `true`
7069
- [`config.active_record.belongs_to_required_validates_foreign_key`](#config-active-record-belongs-to-required-validates-foreign-key): `false`
@@ -2662,24 +2661,6 @@ The default value depends on the `config.load_defaults` target version:
26622661
Determines whether job context for query tags will be automatically updated via
26632662
an `around_perform`. The default value is `true`.
26642663

2665-
#### `config.active_job.use_big_decimal_serializer`
2666-
2667-
Enables the new `BigDecimal` argument serializer, which guarantees
2668-
roundtripping. Without this serializer, some queue adapters may serialize
2669-
`BigDecimal` arguments as simple (non-roundtrippable) strings.
2670-
2671-
WARNING: When deploying an application with multiple replicas, old (pre-Rails
2672-
7.1) replicas will not be able to deserialize `BigDecimal` arguments from this
2673-
serializer. Therefore, this setting should only be enabled after all replicas
2674-
have been successfully upgraded to Rails 7.1.
2675-
2676-
The default value depends on the `config.load_defaults` target version:
2677-
2678-
| Starting with version | The default value is |
2679-
| --------------------- | -------------------- |
2680-
| (original) | `false` |
2681-
| 7.1 | `true` |
2682-
26832664
### Configuring Action Cable
26842665

26852666
#### `config.action_cable.url`

railties/lib/rails/application/configuration.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ def load_defaults(target_version)
305305
action_dispatch.debug_exception_log_level = :error
306306
end
307307

308-
if respond_to?(:active_job)
309-
active_job.use_big_decimal_serializer = true
310-
end
311-
312308
if respond_to?(:active_support)
313309
active_support.cache_format_version = 7.1
314310
active_support.message_serializer = :json_allow_marshal

railties/test/application/configuration_test.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,31 +3107,6 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
31073107
assert_includes ActiveJob::Serializers.serializers, DummySerializer
31083108
end
31093109

3110-
test "use_big_decimal_serializer is enabled in new apps" do
3111-
app "development"
3112-
3113-
assert ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be enabled in new apps"
3114-
end
3115-
3116-
test "use_big_decimal_serializer is disabled if using defaults prior to 7.1" do
3117-
remove_from_config '.*config\.load_defaults.*\n'
3118-
add_to_config 'config.load_defaults "7.0"'
3119-
app "development"
3120-
3121-
assert_not ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be disabled in defaults prior to 7.1"
3122-
end
3123-
3124-
test "use_big_decimal_serializer can be enabled in config" do
3125-
remove_from_config '.*config\.load_defaults.*\n'
3126-
add_to_config 'config.load_defaults "7.0"'
3127-
app_file "config/initializers/new_framework_defaults_7_1.rb", <<-RUBY
3128-
Rails.application.config.active_job.use_big_decimal_serializer = true
3129-
RUBY
3130-
app "development"
3131-
3132-
assert ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be enabled if set in config"
3133-
end
3134-
31353110
test "config.active_job.verbose_enqueue_logs defaults to true in development" do
31363111
build_app
31373112
app "development"

0 commit comments

Comments
 (0)