grape-entity icon indicating copy to clipboard operation
grape-entity copied to clipboard

ArgumentError - because of circular references?

Open udiudi opened this issue 10 years ago • 1 comments

Hey,

I've added Russian Doll caching to an existing endpoint, and I'm getting the strange error below.

This is the code I have:

category = Category.find_by_id(params[:category_id])

ordered_sub_items = Rails.cache.fetch("#{category.cache_key}") do
  active_props = category.active_props

  category.ordered_sub_items.map do |p|
    Rails.cache.fetch("#{p.cache_key}") do 
      category_meta = { position: p.list_pos(category.id), group_id: p.list_group_id(category.id) }

      prop_values = Rails.cache.fetch("#{p.cache_key}/props") do
        active_props.map do |c|
          # data manipulation here..
        end
      end

      OpenStruct.new({
        product: p,
        category_meta: category_meta,
        prop_values: prop_values
      })
    end
  end
end

present ordered_sub_items, with: API::V1::Entities::categoryItem

Error:

ArgumentError - ArgumentError:
  grape-entity (0.4.4) lib/grape_entity/entity.rb:557:in `delegate_attribute'
  grape-entity (0.4.4) lib/grape_entity/entity.rb:543:in `value_for'
  grape-entity (0.4.4) lib/grape_entity/entity.rb:460:in `block in serializable_hash'
  grape-entity (0.4.4) lib/grape_entity/entity.rb:458:in `serializable_hash'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:55:in `block in as_json'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:54:in `as_json'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:215:in `block in as_json'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:215:in `as_json'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:47:in `block in encode'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:46:in `encode'
  activesupport (3.2.21) lib/active_support/json/encoding.rb:31:in `encode'
  activesupport (3.2.21) lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
  grape (0.7.0) lib/grape/formatter/json.rb:6:in `call'
  grape (0.7.0) lib/grape/middleware/formatter.rb:33:in `block in after'
  grape (0.7.0) lib/grape/middleware/formatter.rb:32:in `after'
  grape (0.7.0) lib/grape/middleware/base.rb:25:in `call!'
  grape (0.7.0) lib/grape/middleware/base.rb:18:in `call'
  newrelic_rpm (3.10.0.279) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  grape (0.7.0) lib/grape/middleware/base.rb:24:in `call!'
  grape (0.7.0) lib/grape/middleware/base.rb:18:in `call'
  newrelic_rpm (3.10.0.279) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  grape (0.7.0) lib/grape/middleware/error.rb:26:in `block in call!'
  grape (0.7.0) lib/grape/middleware/error.rb:25:in `call!'
  grape (0.7.0) lib/grape/middleware/base.rb:18:in `call'
  newrelic_rpm (3.10.0.279) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.4.5) lib/rack/head.rb:9:in `call'
  newrelic_rpm (3.10.0.279) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.4.5) lib/rack/builder.rb:134:in `call'
  grape (0.7.0) lib/grape/endpoint.rb:157:in `call!'
  grape (0.7.0) lib/grape/endpoint.rb:145:in `call'
  rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:103:in `optimized_each'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
  rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
  grape (0.7.0) lib/grape/api.rb:537:in `call'
  grape (0.7.0) lib/grape/api.rb:44:in `call!'
  grape (0.7.0) lib/grape/api.rb:40:in `call'

Any ideas what I'm doing wrong?

Thanks

udiudi avatar May 03 '15 15:05 udiudi

I'm getting the same error after updating to the newest version.

reiz avatar May 19 '15 15:05 reiz