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

NameError: uninitialized class variable @@classes in Mongoid::Search #140

Open
rgaufman opened this issue Apr 30, 2020 · 2 comments
Open

Comments

@rgaufman
Copy link

rgaufman commented Apr 30, 2020

When I try to index, I am seeing the following. Any ideas?

$ rake mongoid_search:index`
/usr/local/lib/ruby/gems/2.7.0/gems/mongoid-7.0.5/lib/mongoid.rb:104: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.2/lib/active_support/core_ext/module/delegation.rb:171: warning: The called method `delegate' is defined here
/usr/local/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/usr/local/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/usr/local/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/usr/local/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/usr/local/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/data/deployer/timeline/current/vendor/cache/will_paginate-66f3a4209ec5/lib/will_paginate/deprecation.rb:35: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/data/deployer/timeline/current/vendor/cache/will_paginate-66f3a4209ec5/lib/will_paginate/deprecation.rb:35: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
rake aborted!
NameError: uninitialized class variable @@classes in Mongoid::Search
Did you mean?  class
               class

Tasks: TOP => mongoid_search:index
(See full trace by running task with --trace)

I tried both:

gem 'mongoid_search', github: 'mauriciozaffari/mongoid_search', branch: 'master'

and

gem 'mongoid_search', github: 'mongoid/mongoid_search' 

And the results are the same :(

@rgaufman
Copy link
Author

As a workaround, I added this to make sure each model is "touched" which then allows running klass.index_keywords!:

    mongo_search_models = `find app/models -type f | while read line; do egrep -H "Mongoid::Search" "$line"; done`
    mongo_search_models.split("\n").each do |line|
      name = line.split(':')[0].split('/')[-1].split('.')[0].capitalize
      name.constantize
    end

    Mongoid::Search.classes.each do |klass|
      puts "Indexing Mongoid::Search model: #{klass}"
      klass.index_keywords!
    end

@yads
Copy link
Collaborator

yads commented Jul 8, 2020

Looks like you found this issue in the zeitwerk autoloader rails/rails#37006. @rgaufman can you confirm that running Zeitwerk::Loader.eager_load_all does not help in your case? If the workaround in the issue works I can add a check for zeitwerk and update the existing ::Rails::Application.eager_load! calls to use the zeitwerk one if zeitwerk is defined.

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