RuntimeError: Circular dependency detected while autoloading constant

Mukiza Andrew


I refactored my controllers by introducing request and response models to do some of the logic that was hanging around the controllers following this presentation. I wrapped all the response and request models with a module Responses and Requests respectively. The applications runs perfectly but when I run tests, I get the error below.

Failure/Error: Unable to find matching line from backtrace
RuntimeError:
Circular dependency detected while autoloading constant Responses::FolderContentResponse

My directory structure is as follows:
  - app/
   - models/
     - responses/

Note: I have seen the questions related to this issue but, their issues didn't seem similar to mine. In my case it happens randomly, and only when running tests (RAILS TEST ENV), the application is working perfectly.

module Responses
  class ContentResponse
   include ActiveAttr::Model
   #some attributes
   #some methods
  end
end

module Responses
 class FolderContentResponse < ContentResponse
 end
end

The FolderContent response class inherits from ContentResponse which has more generic methods that FolderContent other content responses use.

Frederick Cheung

This sounds a lot like an issue found recently by Xavier Noria. In a nutshell, capybara boots your application in multithreaded mode for the test even though the setting to load all app code upfront is not activated (needed because require and friends are not threadsafe)

It's been fixed for rails 4.2, on earlier versions

config.allow_concurrency = false

in test.rb should do the trick

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RuntimeError (Circular dependency detected while autoloading constant Apps multithreading

Circular dependency detected while autoloading constant ORDER

`load_missing_constant': Circular dependency detected while autoloading constant ApplicationRecord (RuntimeError)

Error when starting my rails server: Circular dependency detected while autoloading constant AdminUser (RuntimeError)

Circular dependency detected while autoloading constant when loading constant

Rails 4 - Circular dependency detected while autoloading constant Users::TodosController

Override Controller in Spree - Circular dependency detected while autoloading constant

Circular dependency detected with VLOOKUP

A circular dependency was detected in powerbi

railstutorial.org chap 4 full_title_helper.rb causes RuntimeError (Circular dependency detected...)

Circular dependency detected in Angular 7

Angular 4 Circular dependency detected

Angular 4 - Circular dependency detected

Rails autoloading: constants are lost between tests or a circular dependency is introduced

Angular 7 - WARNING in Circular dependency detected:

sqlalchemy.exc.CircularDependencyError: Circular dependency detected

WARNING in Circular dependency detected Compiled with warnings

Circular dependency detected, i can't see it

Power BI why circular dependency is detected

Xamarin.iOS and NuGet: Circular dependency detected

Angular 5: Circular dependency detected between models

(Interface) A circular dependency was detected for the service of type

Angular 5 Circular dependency detected warning

DAX : Using USERELATIONSHIP and getting a circular dependency detected error

Unable to save changes because a circular dependency was detected in the data to be saved

Angular service to service communication and 'circular dependency detected' warnings

ERROR Error: NG0200: Circular dependency in DI detected for DishService

Autofac IOC: Why circular dependency between services detected in runtime?

how to solve Circular dependency detected using Angular 4?