Shopify/tapioca

Tapioca errors when upgrading from GoodJob 4.0.1 to 4.0.2

bdewater-thatch opened this issue · 5 comments

I think this is a Tapioca issue and not a GoodJob one.

I'm upgrading GoodJob to 4.x. I upgraded to 3.99 and ran all the migrations per the instructions. tapioca gem and tapioca dsl run without issue with GoodJob 4.0.0 and 4.0.1, but 4.0.2 causes a ConnectionNotEstablished error (see below for backtrace) when running these Tapioca commands.

I double checked Postgres is still running 😉 and it is. The good_job-4.0.2/app/models/good_job/discrete_execution.rb:18 line before going into Active Record code points to the attribute :duration, :interval line that shipped in bensheldon/good_job#1408 as part of the 4.0.2 release. Since that line seems to be for Rails 6.1 only, I made it conditional and the problem went away: bensheldon/good_job#1412

Backtrace:

/Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/connection_handling.rb:283:in `connection_pool': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/connection_handling.rb:279:in `connection_db_config'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/type.rb:50:in `adapter_name_from'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/attributes.rb:216:in `attribute'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/good_job-4.0.2/app/models/good_job/discrete_execution.rb:18:in `<class:DiscreteExecution>'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/good_job-4.0.2/app/models/good_job/discrete_execution.rb:4:in `<module:GoodJob>'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/good_job-4.0.2/app/models/good_job/discrete_execution.rb:3:in `<main>'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.16/lib/zeitwerk/kernel.rb:26:in `require'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/runtime/reflection.rb:50:in `const_get'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/runtime/reflection.rb:50:in `constantize'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/runtime/trackers/autoload.rb:25:in `block in eager_load_all!'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/runtime/trackers/autoload.rb:50:in `with_disabled_exits'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/runtime/trackers/autoload.rb:20:in `eager_load_all!'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/loaders/gem.rb:69:in `require_gem_file'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/loaders/gem.rb:35:in `load'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/loaders/gem.rb:29:in `load_application'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/commands/abstract_gem.rb:182:in `block in perform_additions'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/shell/basic.rb:46:in `indent'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/commands/abstract_gem.rb:178:in `perform_additions'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/commands/gem_sync.rb:13:in `execute'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/commands/command.rb:27:in `block in run'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca.rb:23:in `block in silence_warnings'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/3.3.0/rubygems/user_interaction.rb:46:in `use_ui'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca.rb:22:in `silence_warnings'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/commands/command.rb:26:in `run'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11473/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/lib/tapioca/cli.rb:308:in `gem'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
	from /Users/bdewater/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/tapioca-0.15.0/exe/tapioca:25:in `<top (required)>'
	from bin/tapioca:29:in `load'
	from bin/tapioca:29:in `<main>'

Does it error if you run GoodJob.const_get(:DiscreteExecution) in console?

It does not error:

GoodJob.const_get(:DiscreteExecution)
=> GoodJob::DiscreteExecution (call 'GoodJob::DiscreteExecution.connection' to establish a connection)

I was poking at lib/active_record/type.rb:50 and noticed the last commit was from attribute should not require a connection is established (rails/rails#41302) which seems to indicate a regression in Rails?

Indeed, I believe it is a rails bug as well. I've openend rails/rails#52311. Why it works in a console, I'm fairly sure it has something to do with it calling Rails.application.initialize! during boot.

Thanks a bunch @Earlopain, I'll close this and we can continue on the Rails issue you opened.