rom-rb / rom

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

'configuration.relations.schema.set' notification is sent when it shouldn't #444

Closed dikond closed 7 years ago

dikond commented 7 years ago

Hi, I've encountered incorrect behavior I believe.

I'm using gem 'rom', '>= 4.0.0.beta2'. The problem appears when I explicitly setup ROM with auto_registration.

The error message is following

NoMethodError: undefined method `indexes' for nil:NilClass

And here is the backtrace

/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-sql-2.0.0.beta2/lib/rom/plugins/relation/sql/auto_restrictions.rb:42:in `restriction_methods'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-sql-2.0.0.beta2/lib/rom/plugins/relation/sql/auto_restrictions.rb:34:in `block in <module:AutoRestrictions>'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/support/notifications.rb:49:in `trigger'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/support/notifications.rb:21:in `block in trigger'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/support/notifications.rb:20:in `each'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/support/notifications.rb:20:in `trigger'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize/finalize_relations.rb:93:in `build_relation'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize/finalize_relations.rb:48:in `block (2 levels) in run!'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize/finalize_relations.rb:31:in `each'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize/finalize_relations.rb:31:in `block in run!'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/relation_registry.rb:7:in `initialize'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/registry.rb:22:in `new'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/registry.rb:22:in `new'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize/finalize_relations.rb:30:in `run!'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize.rb:86:in `load_relations'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/setup/finalize.rb:62:in `run!'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/create_container.rb:34:in `finalize'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/create_container.rb:11:in `initialize'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/create_container.rb:53:in `initialize'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/create_container.rb:58:in `new'
/Users/danny/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rom-core-4.0.0.beta2/lib/rom/create_container.rb:58:in `container'
/Users/danny/dev/<project_name>/system/boot/rom.rb:22:in `block (2 levels) in <top (required)>'
/Users/danny/dev/<project_name>/system/boot/rom.rb:16:in `each'
/Users/danny/dev/<project_name>/system/boot/rom.rb:16:in `each_with_object'
/Users/danny/dev/<project_name>/system/boot/rom.rb:16:in `block in <top (required)>'

The fix seems trivial and I've pushed it to my fork link to commit

I can provide further information about our configuration if you are interested.

flash-gordon commented 7 years ago

This should be fixed in master, you can check it with

gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
  gem 'rom-core'
end
dikond commented 7 years ago

I've updated my Gemfile as you showed, but now I am getting

LoadError: cannot load such file -- rom/attribute

On the line when I'm trying to require it

App::Container.finalize(:rom) do |container|
  require 'rom'

Any hints?)

solnic commented 7 years ago

You need everything from master:

gem "rom", git: "https://github.com/rom-rb/rom.git", branch: "master" do
  gem "rom-core"
  gem "rom-mapper"
  gem "rom-repository"
  gem "rom-changeset"
end

gem "rom-sql", git: "https://github.com/rom-rb/rom-sql", branch: "master"

I had this problem too and I can confirm this is fixed in master. I'll release beta3 later today.

dikond commented 7 years ago

Awesome, thank you!

solnic commented 7 years ago

@dikond FYI I just pushed beta3