Skip to content

Skip triggering "instantiation.active_record" notification when there are no records #52272

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

Merged

Conversation

fatkodima
Copy link
Member

When loading association records, Active Record unnecessary and confusingly triggers an instantiation.active_record notification even when there are no records.

This is not happening when loading records from a regular empty relation

def instantiate_records(rows, &block)
return [].freeze if rows.empty?

I found this bug when subscribed to that event and got a strange payload with 0 count:

ActiveSupport::Notifications.subscribe("instantiation.active_record") do |*, payload|
  puts payload # => {:record_count=>0, :class_name=>"User"}
end

@byroot byroot merged commit 2edad3c into rails:main Jul 5, 2024
@fatkodima fatkodima deleted the skip-triggering-instantiation-notification branch July 5, 2024 08:25
@skipkayhil
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants