samvera / hyrax

Hyrax is a Ruby on Rails Engine built by the Samvera community. Hyrax provides a foundation for creating many different digital repository applications.
http://hyrax.samvera.org/
Apache License 2.0
184 stars 124 forks source link

`AttachFilesToWorkJob` fails with `A copy of Hyrax::Lockable has been removed from the module tree but is still active!` #1307

Open bess opened 7 years ago

bess commented 7 years ago

Descriptive summary

In Hyrax 1.0.1, when I attempt to attach a file to a work via AttachFilesToWorkJob it fails with the error A copy of Hyrax::Lockable has been removed from the module tree but is still active!

Rationale

I need to import legacy data into Hyrax and have it go through the same processing that works uploaded through the UI go through.

Steps to reproduce the behavior

  1. In the rails console, make a hyrax work: etd = FactoryGirl.create(:etd)
  2. Make a Hyrax::UploadedFile object with a file attached: uf = Hyrax::UploadedFile.create(file: File.open("#{::Rails.root}/spec/fixtures/joey/joey_thesis.pdf"))
  3. Attach the Hyrax::UploadedFile object to the work: AttachFilesToWorkJob.perform_now(a, [uf])

It starts to work, makes it through a few jobs, then fails:

ArgumentError: A copy of Hyrax::Lockable has been removed from the module tree but is still active!
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:496:in `load_missing_constant'
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:203:in `const_missing'
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/hyrax-1.0.1/app/services/hyrax/lockable.rb:10:in `lock_manager'
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/hyrax-1.0.1/app/services/hyrax/lockable.rb:6:in `acquire_lock_for'
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/hyrax-1.0.1/app/actors/hyrax/actors/file_set_actor.rb:45:in `attach_file_to_work'
    from /Users/bess/.rvm/gems/ruby-2.3.3@hyrax/gems/hyrax-1.0.1/app/jobs/attach_files_to_work_job.rb:14:in `block in perform'

Possibly related: https://stackoverflow.com/questions/29636334/a-copy-of-xxx-has-been-removed-from-the-module-tree-but-is-still-active

jcoyne commented 7 years ago

Sounds like an autoload problem. Are you running with config.cache_classes=true (this is default with RAILS_ENV=production) that might clear it up.

mjgiarlo commented 7 years ago

@jcoyne @bess Do you suspect this is an issue in master as well?

jcoyne commented 7 years ago

I have never seen this case before, so I have no idea where it may surface.

bess commented 7 years ago

This problem does not exist in our production environment. Hooray! I am also working around it locally by removing the acquire_lock_for(work.id) line while I'm in development mode. Do you consider this an actual bug if it isn't present in the production environment? It seems worth documenting, at least. I'm sure I won't be the last person to encounter this.

atz commented 7 years ago

The bug is real, but autoloading issues are a pain to debug, sometimes relying on system-dependent filesystem ordering.