8000 ActiveSupport 7.2.0 `NameError` from `active_support/delegation.rb:47` · Issue #52582 · rails/rails · GitHub
[go: up one dir, main page]

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

ActiveSupport 7.2.0 NameError from active_support/delegation.rb:47 #52582

Closed
aramprice opened this issue Aug 12, 2024 · 2 comments
Closed

ActiveSupport 7.2.0 NameError from active_support/delegation.rb:47 #52582

aramprice opened this issue Aug 12, 2024 · 2 comments

Comments

@aramprice
Copy link

Steps to reproduce

Create foo.rb with the following contents:

require "active_support/core_ext/module/delegation"

class Foo
  class Bar
    def baz
      puts "baz from #{self.class}"
    end
  end

  delegate :baz, to: Bar
end

puts Foo::Bar.new.baz

Expected behavior

With the latest ActiveSupport (7.2.0) should behave like activesupport-7.1.3.4:

; ruby foo.rb
baz from Foo::Bar
``

### Actual behavior
With `activesupport-7.2.0` the code above produces the following error"

```shell
; ruby foo.rb
~/.gem/ruby/3.2.5/gems/activesupport-7.2.0/lib/active_support/delegation.rb:47:in `generate': uninitialized constant #<Class:ActiveSupport::Delegation>::Inflector (NameError)

          unless Inflector.safe_constantize(to.name).equal?(to)
                 ^^^^^^^^^
	from ~/.gem/ruby/3.2.5/gems/activesupport-7.2.0/lib/active_support/core_ext/module/delegation.rb:161:in `delegate'
	from foo.rb:12:in `<class:Foo>'
	from foo.rb:5:in `<main>'

System configuration

Rails version:
n/a

  • activesupport-7.2.0

Ruby version:

  • ruby-3.2.5
@rafaelfranca
Copy link
Member

Thank you for the issue. Not an issue. You can use active support without requiring the top level file first.

This is documented at https://guides.rubyonrails.org/active_support_core_extensions.html#cherry-picking-a-definition.

Change your script to:

require "active_support"
require "active_support/core_ext/module/delegation"

class Foo
  class Bar
    def baz
      puts "baz from #{self.class}"
    end
  end

  delegate :baz, to: Bar
end

puts Foo::Bar.new.baz

@rafaelfranca rafaelfranca closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2024
@aramprice
Copy link
Author

@rafaelfranca - thanks for the clarification. I'm seeing this issue with factory_bot and will open an issue there.

brucebolt added a commit to alphagov/link-checker-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
brucebolt added a commit to alphagov/publishing-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
brucebolt added a commit to alphagov/link-checker-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
KludgeKML added a commit to alphagov/locations-api that referenced this issue Aug 21, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
KludgeKML added a commit to alphagov/email-alert-api that referenced this issue Aug 21, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
KludgeKML added a commit to alphagov/email-alert-api that referenced this issue Aug 27, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0