1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Backward compatibility to work Marshal.load(legacy_relation.dump)

A relation has a predicate builder, so if a predicate handler which is
referenced by a legacy predicate builder is removed in the new code,
`Marshal.load(legacy_relation.dump)` will fail due to referencing
undefined constant.

I've restored no-op `BaseHandler` constant alias to make cache rotation
easier during Rails 6.1.

Fixes #39601.
This commit is contained in:
Ryuta Kamizono 2020-06-13 09:25:51 +09:00
parent 7118c43599
commit 34d0836f6f
4 changed files with 21 additions and 10 deletions

View file

@ -2,6 +2,17 @@
module ActiveRecord
class PredicateBuilder # :nodoc:
require "active_record/relation/predicate_builder/array_handler"
require "active_record/relation/predicate_builder/basic_object_handler"
require "active_record/relation/predicate_builder/range_handler"
require "active_record/relation/predicate_builder/relation_handler"
require "active_record/relation/predicate_builder/association_query_value"
require "active_record/relation/predicate_builder/polymorphic_array_value"
# No-op BaseHandler to work Mashal.load(File.read("legacy_relation.dump")).
# TODO: Remove the constant alias once Rails 6.1 has released.
BaseHandler = BasicObjectHandler
def initialize(table)
@table = table
@handlers = []
@ -156,11 +167,3 @@ module ActiveRecord
end
end
end
require "active_record/relation/predicate_builder/array_handler"
require "active_record/relation/predicate_builder/basic_object_handler"
require "active_record/relation/predicate_builder/range_handler"
require "active_record/relation/predicate_builder/relation_handler"
require "active_record/relation/predicate_builder/association_query_value"
require "active_record/relation/predicate_builder/polymorphic_array_value"

View file

@ -418,6 +418,14 @@ module ActiveRecord
end
end
def test_marshal_load_legacy_relation
path = File.expand_path(
"support/marshal_compatibility_fixtures/legacy_relation.dump",
TEST_ROOT
)
assert_equal 11, Marshal.load(File.read(path)).size
end
test "no queries on empty IN" do
assert_queries(0) do
Post.where(id: []).load

View file

@ -132,8 +132,8 @@ class YamlSerializationTest < ActiveRecord::TestCase
private
def yaml_fixture(file_name)
path = File.expand_path(
"../support/yaml_compatibility_fixtures/#{file_name}.yml",
__dir__
"support/yaml_compatibility_fixtures/#{file_name}.yml",
TEST_ROOT
)
File.read(path)
end