Fix bug with TypeMap default values
https://github.com/rails/rails/pull/42773 introduced a regression where
looking up an unregistered type on a TypeMap with a parent (like
[mysql2 TYPE_MAP_WITH_BOOLEAN](88ec15b850/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb (L618)
)
would cause a `LocalJumpError`
This commit fixes the error by forwarding the default block when
fetching from the parent TypeMap.
Co-authored-by: Chris Bloom <chrisbloom7@gmail.com>
This commit is contained in:
parent
aae83f4a68
commit
d30c85cebd
|
@ -40,7 +40,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def perform_fetch(lookup_key)
|
def perform_fetch(lookup_key, &block)
|
||||||
matching_pair = @mapping.reverse_each.detect do |key, _|
|
matching_pair = @mapping.reverse_each.detect do |key, _|
|
||||||
key === lookup_key
|
key === lookup_key
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ module ActiveRecord
|
||||||
if matching_pair
|
if matching_pair
|
||||||
matching_pair.last.call(lookup_key)
|
matching_pair.last.call(lookup_key)
|
||||||
elsif @parent
|
elsif @parent
|
||||||
@parent.perform_fetch(lookup_key)
|
@parent.perform_fetch(lookup_key, &block)
|
||||||
else
|
else
|
||||||
yield lookup_key
|
yield lookup_key
|
||||||
end
|
end
|
||||||
|
|
|
@ -143,6 +143,13 @@ module ActiveRecord
|
||||||
assert_equal boolean, mapping.lookup("boolean")
|
assert_equal boolean, mapping.lookup("boolean")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parent_fallback_for_default_type
|
||||||
|
parent = klass.new
|
||||||
|
mapping = klass.new(parent)
|
||||||
|
|
||||||
|
assert_kind_of Value, mapping.lookup(:undefined)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def klass
|
def klass
|
||||||
TypeMap
|
TypeMap
|
||||||
|
|
Loading…
Reference in New Issue