ruby-grape / ruby-grape/grape-entity
Error "Circular dependency detected while autoloading constant" using entities
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with app/api/mysite/entities/v1/order.rb and app/api/mysite/v1/order_api.rb, then reproduce the orders request that reaches the present :orders call. Trace the Ruby/Rails autoloading around Mysite::Entities::V1::Order and its quoted entity references; done means the request no longer raises the circular-dependency error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100