From 54d49a06be7100427d01e1023b0a73131c1ab343 Mon Sep 17 00:00:00 2001 From: Kaan Ozkan Date: Fri, 6 Dec 2024 10:05:54 -0500 Subject: [PATCH] Rescue `ActiveRecord::ConnectionNotEstablished` errors during `const_get` Resolves https://github.com/Shopify/tapioca/issues/2004 --- lib/tapioca/runtime/reflection.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/tapioca/runtime/reflection.rb b/lib/tapioca/runtime/reflection.rb index a17c67883..463e6eea8 100644 --- a/lib/tapioca/runtime/reflection.rb +++ b/lib/tapioca/runtime/reflection.rb @@ -50,6 +50,12 @@ def constantize(symbol, inherit: false, namespace: Object) namespace.const_get(symbol, inherit) rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError UNDEFINED_CONSTANT + rescue => e + if defined?(ActiveRecord) && defined?(ActiveRecord::ConnectionNotEstablished) && e.is_a?(ActiveRecord::ConnectionNotEstablished) + UNDEFINED_CONSTANT + else + raise + end end sig { params(object: BasicObject).returns(T::Class[T.anything]).checked(:never) }