Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "Circular dependency detected while autoloading constant" using entities #179

Open
volonterx opened this issue Oct 6, 2015 · 5 comments
Labels

Comments

@volonterx
Copy link

app/api/mysite/entities/v1/order.rb

module Mysite
  module Entities
    class V1::Order < Mysite::Entities::Base
      expose :id
      expose :state
      expose :cost

      expose :supplier, using: "Mysite::Entities::V1::Supplier"
      expose :office, using: "Mysite::Entities::V1::TheOffice", as: :customer

      expose :order_product_memberships, using: "Mysite::Entities::V1::OrderProductMembership", as: :product

      with_options(format_with: :iso_timestamp) do
        expose :created_at
        expose :updated_at
      end
    end
  end
end

app/api/mysite/v1/order_api.rb

module Mysite
  class V1::OrderAPI < Mysite::API
    resource :orders do
      include Grape::Kaminari
      paginate per_page: 20

      desc "Return a list of orders"
      params do
        requires :api_key
        requires :company_role
        optional :last_time_seen, allow_blank: false
      end
      get do
        company = Company.find_by_api_key!(params[:api_key])
        orders = company.orders_as(params[:company_role]).updated_from(params[:last_time_seen])
        present :orders, paginate(orders), with: Mysite::Entities::V1::Order
      end
...

When I trying to get list of orders via api, I get:

RuntimeError (Circular dependency detected while autoloading constant Mysite::Entities::V1::Order):
  app/api/mysite/v1/order_api.rb:16:in `block (2 levels) in <class:OrderAPI>' 

(in "present :orders...")

Early I have similar problem with
expose :office, using: Mysite::Entities::V1::TheOffice, as: :customer
unless when I moved Mysite::Entities::V1::TheOffice in quotes

Now problem with
with: Mysite::Entities::V1::Order
I have tried many tricks and I think it's a bug.

ruby 2.1.1
rails 4.1.8
grape (0.13.0)
grape-entity (0.4.5)

@dblock dblock added the bug? label Oct 7, 2015
@volonterx
Copy link
Author

Do you have any questions? I can conduct some experiments or anything else.

@dblock
Copy link
Member

dblock commented Oct 8, 2015

Possibly, you could try to write a spec that reproduces this inside this project.

@volonterx
Copy link
Author

I forgot the most important thing! This bug appears only in production environment. For development all is OK.

@dblock
Copy link
Member

dblock commented Oct 9, 2015

Maybe try to build out a minimal project we can play with?

@pre
Copy link

pre commented Apr 26, 2017

Just a sidenote to and old issue: There's now an ability in grape-entity to define the class name as a string. This will help with circular dependencies:

expose :replies, using: "API::Entities::Status", as: :responses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants