mirror of https://github.com/rails/rails
Remove deprecated primitive serializer for `BigDecimal` arguments
This commit is contained in:
parent
ec2c2666c2
commit
2a761d23d2
|
@ -1,2 +1,9 @@
|
|||
* Deprecate `Rails.application.config.active_job.use_big_decimal_serialize`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated primitive serializer for `BigDecimal` arguments.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activejob/CHANGELOG.md) for previous changes.
|
||||
|
|
|
@ -45,13 +45,17 @@ module ActiveJob
|
|||
autoload :TestCase
|
||||
autoload :TestHelper
|
||||
|
||||
##
|
||||
# :singleton-method:
|
||||
# If false, \Rails will preserve the legacy serialization of BigDecimal job arguments as Strings.
|
||||
# If true, \Rails will use the new BigDecimalSerializer to (de)serialize BigDecimal losslessly.
|
||||
# Legacy serialization will be removed in \Rails 7.2, along with this config.
|
||||
singleton_class.attr_accessor :use_big_decimal_serializer
|
||||
self.use_big_decimal_serializer = false
|
||||
def self.use_big_decimal_serializer
|
||||
ActiveJob.deprecator.warn <<-WARNING.squish
|
||||
Rails.application.config.active_job.use_big_decimal_serializer is deprecated and will be removed in Rails 7.3.
|
||||
WARNING
|
||||
end
|
||||
|
||||
def self.use_big_decimal_serializer=(value)
|
||||
ActiveJob.deprecator.warn <<-WARNING.squish
|
||||
Rails.application.config.active_job.use_big_decimal_serializer is deprecated and will be removed in Rails 7.3.
|
||||
WARNING
|
||||
end
|
||||
|
||||
##
|
||||
# :singleton-method:
|
||||
|
|
|
@ -101,15 +101,6 @@ module ActiveJob
|
|||
else
|
||||
if argument.respond_to?(:permitted?) && argument.respond_to?(:to_h)
|
||||
serialize_indifferent_hash(argument.to_h)
|
||||
elsif BigDecimal === argument && !ActiveJob.use_big_decimal_serializer
|
||||
ActiveJob.deprecator.warn(<<~MSG)
|
||||
Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
|
||||
Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
|
||||
|
||||
Note that if your application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
|
||||
This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
|
||||
MSG
|
||||
argument
|
||||
else
|
||||
Serializers.serialize(argument)
|
||||
end
|
||||
|
@ -120,8 +111,6 @@ module ActiveJob
|
|||
case argument
|
||||
when nil, true, false, String, Integer, Float
|
||||
argument
|
||||
when BigDecimal # BigDecimal may have been legacy serialized; Remove in 7.2
|
||||
argument
|
||||
when Array
|
||||
argument.map { |arg| deserialize_argument(arg) }
|
||||
when Hash
|
||||
|
|
|
@ -50,7 +50,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
[ nil, 1, 1.0, 1_000_000_000_000_000_000_000,
|
||||
"a", true, false,
|
||||
"a", true, false, BigDecimal(5),
|
||||
:a,
|
||||
1.day,
|
||||
Date.new(2001, 2, 3),
|
||||
|
@ -81,28 +81,6 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "dangerously treats BigDecimal arguments as primitives not requiring serialization by default" do
|
||||
assert_deprecated(<<~MSG.chomp, ActiveJob.deprecator) do
|
||||
Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
|
||||
Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
|
||||
|
||||
Note that if your application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
|
||||
This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
|
||||
MSG
|
||||
assert_equal(
|
||||
BigDecimal(5),
|
||||
*ActiveJob::Arguments.deserialize(ActiveJob::Arguments.serialize([BigDecimal(5)])),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
test "safely serializes BigDecimal arguments if configured to use_big_decimal_serializer" do
|
||||
# BigDecimal(5) example should be moved back up into array above in Rails 7.2
|
||||
with_big_decimal_serializer do
|
||||
assert_arguments_unchanged BigDecimal(5)
|
||||
end
|
||||
end
|
||||
|
||||
[ Object.new, Person.find("5").to_gid, Class.new ].each do |arg|
|
||||
test "does not serialize #{arg.class}" do
|
||||
assert_raises ActiveJob::SerializationError do
|
||||
|
@ -297,12 +275,4 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
|||
|
||||
JobBuffer.last_value
|
||||
end
|
||||
|
||||
def with_big_decimal_serializer(temporary = true)
|
||||
original = ActiveJob.use_big_decimal_serializer
|
||||
ActiveJob.use_big_decimal_serializer = temporary
|
||||
yield
|
||||
ensure
|
||||
ActiveJob.use_big_decimal_serializer = original
|
||||
end
|
||||
end
|
||||
|
|
|
@ -145,8 +145,12 @@ Please refer to the [Changelog][active-job] for detailed changes.
|
|||
|
||||
### Removals
|
||||
|
||||
* Remove deprecated primitive serializer for `BigDecimal` arguments.
|
||||
|
||||
### Deprecations
|
||||
|
||||
* Deprecate `Rails.application.config.active_job.use_big_decimal_serialize`.
|
||||
|
||||
### Notable changes
|
||||
|
||||
Action Text
|
||||
|
|
|
@ -64,7 +64,6 @@ Below are the default values associated with each target version. In cases of co
|
|||
- [`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" }`
|
||||
- [`config.action_text.sanitizer_vendor`](#config-action-text-sanitizer-vendor): `Rails::HTML::Sanitizer.best_supported_vendor`
|
||||
- [`config.action_view.sanitizer_vendor`](#config-action-view-sanitizer-vendor): `Rails::HTML::Sanitizer.best_supported_vendor`
|
||||
- [`config.active_job.use_big_decimal_serializer`](#config-active-job-use-big-decimal-serializer): `true`
|
||||
- [`config.active_record.allow_deprecated_singular_associations_name`](#config-active-record-allow-deprecated-singular-associations-name): `false`
|
||||
- [`config.active_record.before_committed_on_all_records`](#config-active-record-before-committed-on-all-records): `true`
|
||||
- [`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:
|
|||
Determines whether job context for query tags will be automatically updated via
|
||||
an `around_perform`. The default value is `true`.
|
||||
|
||||
#### `config.active_job.use_big_decimal_serializer`
|
||||
|
||||
Enables the new `BigDecimal` argument serializer, which guarantees
|
||||
roundtripping. Without this serializer, some queue adapters may serialize
|
||||
`BigDecimal` arguments as simple (non-roundtrippable) strings.
|
||||
|
||||
WARNING: When deploying an application with multiple replicas, old (pre-Rails
|
||||
7.1) replicas will not be able to deserialize `BigDecimal` arguments from this
|
||||
serializer. Therefore, this setting should only be enabled after all replicas
|
||||
have been successfully upgraded to Rails 7.1.
|
||||
|
||||
The default value depends on the `config.load_defaults` target version:
|
||||
|
||||
| Starting with version | The default value is |
|
||||
| --------------------- | -------------------- |
|
||||
| (original) | `false` |
|
||||
| 7.1 | `true` |
|
||||
|
||||
### Configuring Action Cable
|
||||
|
||||
#### `config.action_cable.url`
|
||||
|
|
|
@ -305,10 +305,6 @@ module Rails
|
|||
action_dispatch.debug_exception_log_level = :error
|
||||
end
|
||||
|
||||
if respond_to?(:active_job)
|
||||
active_job.use_big_decimal_serializer = true
|
||||
end
|
||||
|
||||
if respond_to?(:active_support)
|
||||
active_support.cache_format_version = 7.1
|
||||
active_support.message_serializer = :json_allow_marshal
|
||||
|
|
|
@ -3107,31 +3107,6 @@ module ApplicationTests
|
|||
assert_includes ActiveJob::Serializers.serializers, DummySerializer
|
||||
end
|
||||
|
||||
test "use_big_decimal_serializer is enabled in new apps" do
|
||||
app "development"
|
||||
|
||||
assert ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be enabled in new apps"
|
||||
end
|
||||
|
||||
test "use_big_decimal_serializer is disabled if using defaults prior to 7.1" do
|
||||
remove_from_config '.*config\.load_defaults.*\n'
|
||||
add_to_config 'config.load_defaults "7.0"'
|
||||
app "development"
|
||||
|
||||
assert_not ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be disabled in defaults prior to 7.1"
|
||||
end
|
||||
|
||||
test "use_big_decimal_serializer can be enabled in config" do
|
||||
remove_from_config '.*config\.load_defaults.*\n'
|
||||
add_to_config 'config.load_defaults "7.0"'
|
||||
app_file "config/initializers/new_framework_defaults_7_1.rb", <<-RUBY
|
||||
Rails.application.config.active_job.use_big_decimal_serializer = true
|
||||
RUBY
|
||||
app "development"
|
||||
|
||||
assert ActiveJob.use_big_decimal_serializer, "use_big_decimal_serializer should be enabled if set in config"
|
||||
end
|
||||
|
||||
test "config.active_job.verbose_enqueue_logs defaults to true in development" do
|
||||
build_app
|
||||
app "development"
|
||||
|
|
Loading…
Reference in New Issue