gregnavis / active_record_doctor

Identify database issues before they hit production.
MIT License
1.76k stars 55 forks source link

Fails with wrong class_name: "NameError: NameError: uninitialized constant" #182

Open frsantos opened 2 months ago

frsantos commented 2 months ago

Hi!, thank you for the gem.

We are currently evaluating it, but it fails with the following case: we had a relation defined with a wrong class_name, as the model was removed but we didn't remove the associated has_many:

has_many :logbooks_assets_images, class_name: '::Assets::Image'

Running the gem it raises and stops processing instead of reporting an issue:

NameError: uninitialized constant ::Assets::Image
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/inflector/methods.rb:284:in `const_get'
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/inflector/methods.rb:284:in `block in constantize'
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/inflector/methods.rb:280:in `each'
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/inflector/methods.rb:280:in `inject'
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/inflector/methods.rb:280:in `constantize'
/usr/local/bundle/gems/activesupport-6.0.5.1/lib/active_support/dependencies/zeitwerk_integration.rb:19:in `constantize'
/usr/local/bundle/gems/activerecord-6.0.5.1/lib/active_record/inheritance.rb:185:in `compute_type'
/usr/local/bundle/gems/activerecord-6.0.5.1/lib/active_record/reflection.rb:423:in `compute_class'
/usr/local/bundle/gems/activerecord-6.0.5.1/lib/active_record/reflection.rb:380:in `klass'
/usr/local/bundle/gems/active_record_doctor-1.14.0/lib/active_record_doctor/detectors/incorrect_dependent_option.rb:90:in `block (2 levels) in detect'
/usr/local/bundle/gems/active_record_doctor-1.14.0/lib/active_record_doctor/detectors/base.rb:318:in `block (3 levels) in each_association'
/usr/local/bundle/gems/active_record_doctor-1.14.0/lib/active_record_doctor/logger/dummy.rb:7:in `log'
/usr/local/bundle/gems/active_record_doctor-1.14.0/lib/active_record_doctor/detectors/base.rb:96:in `log'
fatkodima commented 2 months ago

Basically same as https://github.com/gregnavis/active_record_doctor/issues/181.