Use call_args
in the define_proxy_method
namespace.
#48844
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Substitutes #48843
define_proxy_call
acceptscall_args
as an argument which impacts method body generation but it doesn't usecall_args
in thenamespace
generation which leads to the same cached method to be reused even ifcall_args
differ.It has never been an issue since
define_proxy_call
was only used to generate Active Record attribute methods and we were always passing the samecall_args
per method name.However, since #48533 we are using
define_proxy_call
to generate alias attribute methods wherecall_args
differ for the same method name which leads to the same cached method being reused in wrong places.This commit fixes the issue by making sure
call_args
are being considered when generating thenamespace
for the method as anything that results in a different body being generated should be accounted when building the cache keyProblem example
Consider the following models:
Since #48533 we expect Rails to generate the following getters for aliases:
Due to Rails using caching mechanism for method generation and the cache key consists of the hardcoded
proxy_alias_attribute
plus theproxy_target
which is"attribute"
only onesubject
getter method will actually be generated and it depends on whichever of the models gets loaded first, the other model will reuse the cached method with a wrong body