Skip to content
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

Add missing require to active_support/callbacks.rb #42172

Merged

Conversation

okuramasafumi
Copy link
Contributor

Summary

At line 353, blank? method is called.
We need to require "active_support/core_ext/object/blank" for blank? to be available.

Other Information

This is a fix for a subtle bug in ActiveSupport::Callbacks.
It was (at least I think) trivial so I didn't create an issue for it but instead fixed it in this PR.

require 'active_support/callbacks'

class Record
  include ActiveSupport::Callbacks
  define_callbacks :save

  def save
    run_callbacks :save do
      puts "- save"
    end
  end
end

class PersonRecord < Record
  set_callback :save, :before, :saving_message
  def saving_message
    puts "saving..."
  end

  set_callback :save, :after do |object|
    puts "saved"
  end
end

This code (from Rails official doc plus require) doesn't work due to the error in version 6.1.3.1 of `activesupport'.

/Users/okuramasafumi/.gem/ruby/3.0.1/gems/activesupport-6.1.3.1/lib/active_support/callbacks.rb:356:in `check_conditionals': undefined method `blank?' for nil:NilClass (NoMethodError)

After adding require 'active_support/core_ext/object/blank' it started working as expected.

This bug seems to be introduced in 0740adb.

At line 353, `blank?` method is called.
We need to `require "active_support/core_ext/object/blank"`
for `blank?` to be available.
@kamipo kamipo merged commit 70b6cee into rails:main May 8, 2021
@okuramasafumi okuramasafumi deleted the require-object-blank-in-as-callbacks branch May 8, 2021 11:23
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.

None yet

2 participants