Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2625

Storing mongoid relationships in cache raise no _dump_data is defined for class Proc

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.15
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Consider a person with an account. A person can be successfully written to cache, but relationships cannot.

       ruby
      require "spec_helper"
      
      describe ActiveSupport::Cache do
      
        let(:cache) do
          ActiveSupport::Cache::MemoryStore.new
        end
      
        describe "#fetch" do
      
          let!(:person) do
            Person.new
          end
      
          let!(:account) do
            person.create_account(name: "savings")
          end
      
          it "stores the parent object" do
            cache.fetch "key" do
              person
            end.should eq person
            cache.fetch "key" do
            end.should eq person
          end
      
          it "stores the embedded object" do
            cache.fetch "key" do
              account
            end.should eq account
            cache.fetch "key" do
            end.should eq account
          end
      
        end
      end
      
      ActiveSupport::Cache
        #fetch
          stores the parent object (FAILED - 1)
          stores the embedded object (FAILED - 2)
      
      Failures:
      
        1) ActiveSupport::Cache#fetch stores the parent object
           Failure/Error: cache.fetch "key" do
           TypeError:
             no _dump_data is defined for class Proc
           # ./spec/mongoid/cache_spec.rb:20:in `block (3 levels) in <top (required)>'
      
        2) ActiveSupport::Cache#fetch stores the embedded object
           Failure/Error: cache.fetch "key" do
           TypeError:
             no _dump_data is defined for class Proc
           # ./spec/mongoid/cache_spec.rb:28:in `block (3 levels) in <top (required)>'
      

      This gets worse in Rails, where with a FileStore you actually get no error depending on the cache store and the deserialized object is a String. With Dalli you get another error: {{ Unable to unmarshal value: instance of Mongoid::Relations::Referenced::One needs to have method }}marshal_load'`.

            Assignee:
            durran Durran Jordan
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: