rom
rom copied to clipboard
Relation with name `:schema' causes registration problems
Describe the bug
Non-aliased schema name :schema
appears to cause relation registration problems.
To Reproduce
My relation has this configuration snippet:
schema(:schema) do
...
end
When I register the relation with a configuration, create a container with the config, then access the relation:
contianer.relations[:schema]
I get an error:
16: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize.rb:88:in `load_relations'
15: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize/finalize_relations.rb:32:in `run!'
14: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/registry.rb:31:in `new'
13: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/registry.rb:31:in `new'
12: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/relation_registry.rb:11:in `initialize'
11: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize/finalize_relations.rb:33:in `block in run!'
10: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize/finalize_relations.rb:33:in `each'
9: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize/finalize_relations.rb:50:in `block (2 levels) in run!'
8: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/setup/finalize/finalize_relations.rb:108:in `build_relation'
7: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/support/memoizable.rb:15:in `new'
6: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/support/memoizable.rb:15:in `new'
5: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/dry-initializer-3.0.4/lib/dry/initializer/mixin/root.rb:7:in `initialize'
4: from (eval):18:in `__dry_initializer_initialize__'
3: from (eval):18:in `instance_exec'
2: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/relation.rb:154:in `block in <class:Relation>'
1: from /Users/dc/.rvm/gems/ruby-2.6.5@solrbee/gems/rom-core-5.2.3/lib/rom/plugins/relation/registry_reader.rb:38:in `block (2 levels) in define_readers!'
NoMethodError (undefined method `[]' for nil:NilClass)
If I change the relation config to alias the name `:schema':
schema(:schema, as: :foo_schema) do
...
end
then
container.relations[:foo_schema]
works as expected.
Expected behavior
If :schema
needs to be reserved, then registration should emit appropriate advice on failure, such as "cannot use name reserved name ':schema' in relation registry". Otherwise, registration would work as normal.
Your environment
- Affects my production application: NO
- Ruby version: 2.6.5
- OS: MacOS Catalina 10.15.7