Skip to content

Commit d30c85c

Browse files
Fix bug with TypeMap default values
rails#42773 introduced a regression where looking up an unregistered type on a TypeMap with a parent (like [mysql2 TYPE_MAP_WITH_BOOLEAN](https://github.com/rails/rails/blob/88ec15b850790a06bd8dcfe59ca05d865f458c7c/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 <[email protected]>
1 parent aae83f4 commit d30c85c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

activerecord/lib/active_record/type/type_map.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ def alias_type(key, target_key)
4040
end
4141

4242
protected
43-
def perform_fetch(lookup_key)
43+
def perform_fetch(lookup_key, &block)
4444
matching_pair = @mapping.reverse_each.detect do |key, _|
4545
key === lookup_key
4646
end
4747

4848
if matching_pair
4949
matching_pair.last.call(lookup_key)
5050
elsif @parent
51-
@parent.perform_fetch(lookup_key)
51+
@parent.perform_fetch(lookup_key, &block)
5252
else
5353
yield lookup_key
5454
end

activerecord/test/cases/type/type_map_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ def test_parent_fallback
143143
assert_equal boolean, mapping.lookup("boolean")
144144
end
145145

146+
def test_parent_fallback_for_default_type
147+
parent = klass.new
148+
mapping = klass.new(parent)
149+
150+
assert_kind_of Value, mapping.lookup(:undefined)
151+
end
152+
146153
private
147154
def klass
148155
TypeMap

0 commit comments

Comments
 (0)