Skip to content

Commit

Permalink
Merge pull request rails#51713 from Shopify/stale-state-casting
Browse files Browse the repository at this point in the history
Don't cast `stale_state` to String
  • Loading branch information
byroot authored May 2, 2024
2 parents 8ba2b7f + 2cadcb2 commit 087260d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def invertible_for?(record)
end

def stale_state
result = owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
result && result.to_s
owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def raise_on_type_mismatch!(record)
end

def stale_state
foreign_key = super
foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s]
if foreign_key = super
[foreign_key, owner[reflection.foreign_type]]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def construct_join_attributes(*records)
def stale_state
if through_reflection.belongs_to?
Array(through_reflection.foreign_key).filter_map do |foreign_key_column|
owner[foreign_key_column] && owner[foreign_key_column].to_s
owner[foreign_key_column]
end.presence
end
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/marshal_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_deserializing_rails_6_1_marshal_with_loaded_association_cache
assert_equal "Have a nice day", topic.content
assert_predicate topic.association(:replies), :loaded?
assert_predicate topic.replies.first.association(:topic), :loaded?
assert_same topic, topic.replies.first.topic
end

def test_deserializing_rails_7_1_marshal_basic
Expand Down

0 comments on commit 087260d

Please sign in to comment.