rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.09k stars 161 forks source link

Unclear error when schema class is undefined. #376

Closed cflipse closed 7 years ago

cflipse commented 7 years ago

Just chased down an error in rom-rails that is due to a dummy adapter being built for the specs, and the breaking changes in rom 3.0:

The fix is here: https://github.com/rom-rb/rom-rails/commit/198f99906713dea713fda5c296f65f28d747957c

However, nothing in the backtrace leads to this place:

NoMethodError: undefined method `define' for nil:NilClass
  /home/flip/src/rom-rb/rom/lib/rom/schema/dsl.rb:52:in `call'
  /home/flip/src/rom-rb/rom/lib/rom/relation/class_interface.rb:174:in `schema'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:53:in `build_relation'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:25:in `block (2 levels) in run!'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:24:in `each'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:24:in `block in run!'
  /home/flip/src/rom-rb/rom/lib/rom/relation_registry.rb:6:in `initialize'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:23:in `new'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize/finalize_relations.rb:23:in `run!'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize.rb:93:in `load_relations'
  /home/flip/src/rom-rb/rom/lib/rom/setup/finalize.rb:62:in `run!'
  /home/flip/src/rom-rb/rom/lib/rom/create_container.rb:33:in `finalize'
  /home/flip/src/rom-rb/rom/lib/rom/create_container.rb:11:in `initialize'
  /home/flip/src/rom-rb/rom/lib/rom/create_container.rb:52:in `initialize'
  /home/flip/src/rom-rb/rom/lib/rom/create_container.rb:57:in `new'
  /home/flip/src/rom-rb/rom/lib/rom/create_container.rb:57:in `container'
  /home/flip/src/rom-rb/rom-rails/lib/rom/rails/railtie.rb:79:in `create_container'
  /home/flip/.gem/ruby/2.2.3/gems/railties-5.0.1/lib/rails/railtie.rb:193:in `public_send'
  /home/flip/.gem/ruby/2.2.3/gems/railties-5.0.1/lib/rails/railtie.rb:193:in `method_missing'
  /home/flip/src/rom-rb/rom-rails/lib/rom/rails/railtie.rb:44:in `block in <class:Railtie>'
 # ... more Rails initializer stuff ignored

An unspecified schema_class should either default to an error, or should propogate with a default Schema

cflipse commented 7 years ago

The default given in the schema/dsl initializer is more or less irreleveant, as the key is always provided in production code. The place too look is more likely in the inheritance hooks for ROM::Relation