consistency_fail icon indicating copy to clipboard operation
consistency_fail copied to clipboard

Incompatible with Rails 6, private method `require_dependency' called for Kernel:Module

Open alphabt opened this issue 5 years ago • 3 comments

Looks like require_dependency is biting us against. This time it fails with Rails 6.

$ consistency_fail
Traceback (most recent call last):
	8: from /Users/user/.rbenv/versions/2.6.1/bin/consistency_fail:23:in `<main>'
	7: from /Users/user/.rbenv/versions/2.6.1/bin/consistency_fail:23:in `load'
	6: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/bin/consistency_fail:20:in `<top (required)>'
	5: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail.rb:11:in `run'
	4: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail/models.rb:19:in `preload_all'
	3: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail/models.rb:19:in `each'
	2: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail/models.rb:21:in `block in preload_all'
	1: from /Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail/models.rb:21:in `each'
/Users/user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/consistency_fail-0.3.7/lib/consistency_fail/models.rb:22:in `block (2 levels) in preload_all': private method `require_dependency' called for Kernel:Module (NoMethodError)
Did you mean?  require_relative

Gemfile

gem 'rails', '~> 6.0.0.rc1'

According to https://weblog.rubyonrails.org/2019/1/18/Rails-6-0-Action-Mailbox-Action-Text-Multiple-DBs-Parallel-Testing/

Finally, you should pay attention to Xavier Noria’s new Zeitwerk code loader for Ruby. It didn’t make the integration cut for beta1, but starting with beta2, it’ll be the new autoloader for Rails. Be prepared to say goodbye to any lingering require or require_dependency calls in your code!

Not sure if Rails 6 switching to Zeitwerk is relevant to solving the use of require_dependency in consistency_fail.

alphabt avatar May 13 '19 06:05 alphabt

Ah, yeah moved to private, OK. So maybe we can add a check for Rails version, and if it's 6+, change the require_dependency to require?

trptcolin avatar May 14 '19 17:05 trptcolin

Changing behavior with a version check should be ok. But I'm not sure if require will work since we tried that last time and it caused a regression with enum per https://github.com/trptcolin/consistency_fail/issues/47.

I haven't done much research into what to use for Rails 6 yet. If I do find something I'll definitely share it here.

alphabt avatar May 16 '19 13:05 alphabt

Ah, yeah I guess I was making an assumption there based on the "eliminates all known use cases for require_dependency, including STIs" language in this Zeitwerk blog post - but on re-reading I think it might be more complicated, since the advice on the Rails announcement is about dropping the need for both require and require_dependency...

trptcolin avatar May 16 '19 13:05 trptcolin