active-hash / active_hash

A readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
MIT License
1.21k stars 179 forks source link

Reflection Inheritance Issue #279

Closed daBee closed 11 months ago

daBee commented 1 year ago

Both in Ruby 3.1.2 and Ruby 3.2.2, I am finding this:

/Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/active_hash-3.2.0/lib/associations/reflection_extensions.rb:3:in `<module:Reflection>': uninitialized constant ActiveHash::Reflection::ActiveRecord (NameError)

    class BelongsToReflection < ActiveRecord::Reflection::BelongsToReflection
                                ^^^^^^^^^^^^
Did you mean?  ActiveModel
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/active_hash-3.2.0/lib/associations/reflection_extensions.rb:2:in `<module:ActiveHash>'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/active_hash-3.2.0/lib/associations/reflection_extensions.rb:1:in `<top (required)>'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/active_hash-3.2.0/lib/associations/associations.rb:95:in `require_relative'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/active_hash-3.2.0/lib/associations/associations.rb:95:in `included'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/canada_eh-0.0.5/lib/canada_eh.rb:20:in `include'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/canada_eh-0.0.5/lib/canada_eh.rb:20:in `<class:Province>'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/canada_eh-0.0.5/lib/canada_eh.rb:17:in `<module:CanadaEh>'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/canada_eh-0.0.5/lib/canada_eh.rb:4:in `<top (required)>'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:60:in `require'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:55:in `each'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:55:in `block in require'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:44:in `each'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler/runtime.rb:44:in `require'
    from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.12/lib/bundler.rb:196:in `require'
    from /Users/user3/zz_before.rb:7:in `<top (required)>'
    from /users/user3/app.rb:9:in `require_relative'
    from /users/user3/app.rb:9:in `<main>'
kbrock commented 1 year ago

Hello @daBee

Could you share the version of Rails you are running? (ActiveRecord is defined in rails) Or are you just including ActiveSupport and ActiveRecord?

What are you doing to produce this problem?

[master] active_hash $ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
[master] active_hash $ bundle exec rake
/Users/kbrock/.rubies/ruby-3.2.2/bin/ruby -I/Users/kbrock/.gem/ruby/3.2.2/gems/rspec-core-3.12.1/lib:/Users/kbrock/.gem/ruby/3.2.2/gems/rspec-support-3.12.0/lib /Users/kbrock/.gem/ruby/3.2.2/gems/rspec-core-3.12.1/exe/rspec --pattern spec/\*\*/\*_spec.rb
...........................................................................................................................................................................................................................................................................................................................................................

Finished in 0.36826 seconds (files took 0.80767 seconds to load)
347 examples, 0 failures

[master] active_hash $ grep rails Gemfile.lock
[master] active_hash $ grep active Gemfile.lock
    active_hash (3.2.0)
      activesupport (>= 5.0.0)
    activemodel (7.0.4.2)
      activesupport (= 7.0.4.2)
    activerecord (7.0.4.2)
      activemodel (= 7.0.4.2)
      activesupport (= 7.0.4.2)
    activesupport (7.0.4.2)
  active_hash!
  activerecord (>= 5.0.0)
  activerecord-jdbcsqlite3-adapter (>= 1.3.6)

Hopefully we should be able to get you up and running quickly.

daBee commented 1 year ago

No Rails. Ruby only. I'm running a script that has Bundle.require up front.

Gemfile does not have this, but Gemfile.lock has it as a spec, and is called by canada_eh.

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

kbrock commented 11 months ago
  1. Has this been solved by https://github.com/alphagov/contacts-admin/pull/1167 ?
  2. Could you provide a reproducer or more details about what you are doing to get this error? Could you provide a pointer to gem canada_eh? This is not available on ruby gems
daBee commented 11 months ago

I can't find it either. I've been looking for it for some time. I guess it's gone.