-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused method_missing
definition
#15694
Conversation
# see if we've created the method we're looking for. | ||
def method_missing(method, *args, &block) # :nodoc: | ||
self.class.define_attribute_methods | ||
if respond_to_without_attributes?(method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method still required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's used within ActiveModel
Should |
Updated |
We always define attribute methods in the constructor or in `init_with`.
❤️ not using |
It's eager on calling |
Right. But e.g. someone may have included a of module defining a virtual attribute into their class before instantiating it. If doing so was never part of public API, I guess it's up to user to deal with. But it may be nice to have release notes warning upgrading users of this change. |
That will still work. We have tests doing exactly that. |
Remove unused `method_missing` definition
84cf156 (PR rails#15694) introduced a subtle regression. There are actually three distinct entry points to creating an AR object – via .new (i.e. #initialize), via #init_with (e.g. from YAML or database queries) and via .allocate. With the patch in 84cf156, attribute methods and respond_to? will not work correctly when objects are allocated directly, without going through either The reason this test case didn't catch the regression was that the `Topic` class is shared between test cases, so by the time this test case is ran the attribute methods are very likely to be defined. Switching to use a fresh anonymous class in the test to ensure we surface this problem in the future.
We always define attribute methods in the constructor or in
init_with
.