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
Define missing attribute methods from method_missing
#50594
Conversation
aa44aab
to
3aca935
Compare
Ref: mastodon/mastodon#27622 If applications don't eager load and use the old Rails 6.1 Marshal format, they can load Active Record instances from caches without calling `init_internals` hence attribute methods and aliases are nnot defined yet, leading to `NoMethodError` Initially I was hopping to fully get rid of the `define_attribute_methods` call in `init_internals` in favor of this new method missing, as it would remove work from the happy path, unfortunately that isn't possible because if a generated method overrides a default method inherited from object, `method_missing` won't be called. e.g. `Kernel#format` We may want to get rid of this extra code once we remove support for the 6.1 marshal format.
3aca935
to
a0993f8
Compare
Backported to 7-1-stable. |
@byroot did the backport not get pushed up? I'm not seeing it on |
yeah I forgot to push 😫 . It's now at f7255ec |
@byroot I think isn't backported yet. I don't see this code in the branch. https://github.com/rails/rails/commits/7-1-stable/activerecord/lib/active_record/model_schema.rb There is a changelog entry for it, but no other code change went, and the commit message is wrong. |
Hum, I must have borked my merge, I will have a look. |
Ref: rails#50594 Define missing attribute methods from `method_missing`
Ref: rails#50594 Define missing attribute methods from `method_missing`
@byroot @rafaelfranca I noticed because motor-admin-rails uses this pattern with the audited gem. Setup: class Audit < ApplicationRecord
belongs_to :auditable, polymorphic: true
end
class MotorAudit < Audit
self.table_name = 'motor_audits'
end
class Article < ApplicationRecord
has_many :audits, as: :auditable, class_name: "MotorAudit", inverse_of: :auditable
end
create_table :motor_audits do |t|
t.column :auditable_id, :string
t.column :auditable_type, :string
end
create_table :articles do |t|
t.timestamps
end Rails 7.1.3.2:
Rails 7.2.0.alpha:
|
If the table doesn't exist, shouldn't If that doesn't solve your problem, please open an issue with a repro script, and I'll figure a solution. |
Not sure. But at least I wanted to mention that the behaviour is now changed. |
Of course, but to be clear, if that behavior wasn't supported nor documented in the first place but just happened to work by accident, it's not a concern. |
Pinging @omohokcoj as motor-admin-rails maintainer. |
Ref: mastodon/mastodon#27622
If applications don't eager load and use the old Rails 6.1 Marshal format, they can load Active Record instances from caches without calling
init_internals
hence attribute methods and aliases are nnot defined yet, leading toNoMethodError
Initially I was hopping to fully get rid of the
define_attribute_methods
call ininit_internals
in favor of this new method missing, as it would remove work from the happy path, unfortunately that isn't possible because if a generated method overrides a default method inherited from object,method_missing
won't be called. e.g.Kernel#format
We may want to get rid of this extra code once we remove support for the 6.1 marshal format.
cc @ClearlyClaire
FYI: @nvasilevski