2017-01-26 4 views
1

배포 후 Heroku에서이 오류가 발생하지만 오류가 발생하지 않거나이 문제가 로컬에서 발생하지 않습니다.Heroku/Ruby에서 "순환 적 종속성이 자동 상수 동안 검색 됨"오류를 수정하는 방법

다음 이름/네임 스페이스 등의 문제는 무엇입니까? 내가 뭘 놓치고 있니?

모델/문제/구매/finalize_utils.rb

module Purchase::FinalizeUtils 
    extend ActiveSupport::Concern 
end 

모델/purchase.rb

class Purchase < ActiveRecord::Base 
    include FinalizeUtils 
end 

로그 오류 : 그것은 미래의 사람들을위한 가치 무엇이 들어

2017-01-26T22:39:25.553902+00:00 app[web.1]: RuntimeError: Circular dependency detected while autoloading constant Purchase::FinalizeUtils 
2017-01-26T22:39:25.553903+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:492:in `load_missing_constant' 
2017-01-26T22:39:25.553903+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184:in `const_missing' 
2017-01-26T22:39:25.553904+00:00 app[web.1]: /app/app/models/purchase.rb:19:in `<class:Purchase>' 
2017-01-26T22:39:25.553904+00:00 app[web.1]: /app/app/models/purchase.rb:16:in `<top (required)>' 
2017-01-26T22:39:25.553905+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require' 
2017-01-26T22:39:25.553906+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require' 
2017-01-26T22:39:25.553906+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency' 
2017-01-26T22:39:25.553907+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require' 
2017-01-26T22:39:25.553907+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:360:in `require_or_load' 
2017-01-26T22:39:25.553907+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494:in `load_missing_constant' 
2017-01-26T22:39:25.553908+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184:in `const_missing' 
2017-01-26T22:39:25.553909+00:00 app[web.1]: /app/app/models/concerns/purchase/finalize_utils.rb:1:in `<top (required)>' 
2017-01-26T22:39:25.553909+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require' 
2017-01-26T22:39:25.553909+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require' 
2017-01-26T22:39:25.553910+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency' 
2017-01-26T22:39:25.553910+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require' 
2017-01-26T22:39:25.553910+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:360:in `require_or_load' 
2017-01-26T22:39:25.553911+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:317:in `depend_on' 
2017-01-26T22:39:25.553912+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!' 
2017-01-26T22:39:25.553911+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:233:in `require_dependency' 
2017-01-26T22:39:25.553912+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:471:in `each' 
2017-01-26T22:39:25.553912+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:471:in `block in eager_load!' 
2017-01-26T22:39:25.553913+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:469:in `each' 
2017-01-26T22:39:25.553913+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:469:in `eager_load!' 
2017-01-26T22:39:25.553914+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:346:in `eager_load!' 
2017-01-26T22:39:25.553914+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application/finisher.rb:56:in `each' 
2017-01-26T22:39:25.553914+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>' 
2017-01-26T22:39:25.553915+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `instance_exec' 
2017-01-26T22:39:25.553915+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `run' 
2017-01-26T22:39:25.553915+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:55:in `block in run_initializers' 
2017-01-26T22:39:25.553916+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each' 
2017-01-26T22:39:25.553916+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 
2017-01-26T22:39:25.553917+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from' 
2017-01-26T22:39:25.553917+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component' 
2017-01-26T22:39:25.553917+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each' 
2017-01-26T22:39:25.553918+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call' 
2017-01-26T22:39:25.553918+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component' 
2017-01-26T22:39:25.553918+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each' 
2017-01-26T22:39:25.553919+00:00 app[web.1]: /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each' 
2017-01-26T22:39:25.553921+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:54:in `run_initializers' 
2017-01-26T22:39:25.553921+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:352:in `initialize!' 
2017-01-26T22:39:25.553922+00:00 app[web.1]: /app/config/environment.rb:11:in `<top (required)>' 
+0

확인 http://stackoverflow.com/questions/28682451/circular-dependency-on-nested-concern –

답변

1

이 문제는 내 문제가 사물의 조합이라는 것을 발견했습니다. 하나

이 생산 및 개발이 설정했습니다 다른 경우 작동 된 이유 :

config.eager_load 

이 비슷한 "설정"에 대한 실패하지 않은되지 않은 이유 (즉, 사용자 :: 인 MyModule) eager_loading을 위해 파일을 처리하는 순서와 관련이있는 것 같습니다.

문제는 모델 이전에 문제가 발생하는 것처럼 보였을 때가 있었고 때로는 그 반대의 경우도있었습니다. 클래스 구매가 동일한 클래스로 보이지 않았기 때문에 두 버전 모두에 문제가 있습니다 (하나는 하위 클래스 였고 하나는 그렇지 않았기 때문에). 제대로 다시 열리지 않았습니다.

그래서 나는이를 변경하기 위해 필요한이에

module Purchase::FinalizeUtils 
    extend ActiveSupport::Concern 
end 

:

#models/concerns/purchase/finalize_utils.rb 
class Purchase < ActiveRecord::Base 
    module FinalizeUtils 
    extend ActiveSupport::Concern 
    end 
    end 
end 

를이 클래스 구매가 재개 대신 재정의 할 수있었습니다. 아니면 그런 식으로. 저 같이 포함 내 우려를 네임 스페이스 할 수 있습니다 위의 방법 중 하나의 방법 :

파일은 게으른 로딩에 의해 발견되는 이름,하지만 모듈이 클래스에 있기 때문에, 조회 경로가 발견되지

#models/purchase.rb 
class Purchase < ActiveRecord::Base 
    include FinalizeUtils 
end 
.