Is it possible to use closure_tree outside a rails application?
iamrahulroy opened this issue · 2 comments
Trying to integrate Closure Tree with Ruby Serverless application based on Jets Framework.
The issue is, the moment I put has_closure_tree method inside the model, it starts throwing weird errors.
Error:
`connection_pool': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
Traceback:
Traceback (most recent call last):
35: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/bin/ruby_executable_hooks:24:in `<main>'
34: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/bin/ruby_executable_hooks:24:in `eval'
33: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/bin/jets:23:in `<main>'
32: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/bin/jets:23:in `load'
31: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/exe/jets:14:in `<top (required)>'
30: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/cli.rb:5:in `start'
29: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/cli.rb:20:in `start'
28: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/cli.rb:48:in `boot_jets'
27: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/core.rb:18:in `boot'
26: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/booter.rb:24:in `boot!'
25: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/booter.rb:201:in `eager_load_app'
24: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/booter.rb:201:in `select'
23: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/jets-1.8.9/lib/jets/booter.rb:218:in `block in eager_load_app'
22: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/core_ext/string/inflections.rb:68:in `constantize'
21: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:281:in `constantize'
20: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:281:in `inject'
19: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:281:in `each'
18: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:283:in `block in constantize'
17: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:283:in `const_get'
16: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:195:in `const_missing'
15: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:510:in `load_missing_constant'
14: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:356:in `require_or_load'
13: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in `load_interlock'
12: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:13:in `loading'
11: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
10: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
9: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in `block in load_interlock'
8: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:373:in `block in require_or_load'
7: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:475:in `load_file'
6: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:661:in `new_constants_in'
5: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:476:in `block in load_file'
4: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:476:in `load'
3: from /Users/rahul/instant_systems/dms-projects/dms_backend_api/app/models/document.rb:58:in `<top (required)>'
2: from /Users/rahul/instant_systems/dms-projects/dms_backend_api/app/models/document.rb:67:in `<class:Document>'
1: from /Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/closure_tree-7.0.0/lib/closure_tree/has_closure_tree.rb:35:in `has_closure_tree'
/Users/rahul/.rvm/gems/ruby-2.5.5@jets-gemset/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:114:in `connection_pool': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
The error occurs when I run jets console. It disappears the moment I remove has_closure_tree method from my model.
EDIT: connection_pool.release_connection inside has_closure_tree method is causing the issue with jets.
@iamtheschmitzer closure_tree bounded to the activerecord. Answer is yes, but only if you will use activerecord gem. :)
It looks like a load order problem. Please initialize ActiveRecord, including loading the database configuration and establishing a connection, before loading your models.
The principle applies in rails also. It isn't clearly documented, but you aren't supposed to use ActiveRecord models until the app is fully initialized.