Git Product home page Git Product logo

Comments (9)

seattlecyclist avatar seattlecyclist commented on July 26, 2024 2

@ramontayag - With regard to the error @topherfangio reported. I work with him. Here is a failing spec. Just drop it into your storext_spec.rb and run it.

  it "can properly marshal" do
    author = Author.new(name: "A. Clarke")
    expect{Marshal.dump(author)}.to_not raise_exception(TypeError)
  end

/edit Marshal.dump is used by memcache when you try to cache an object. So this use case is 'common' IMHO.

# this will fail.  
Rails.cache.fetch("a_user") do
   User.find(1)
end

Edit 2/ Docs on the Marshal.dump method https://ruby-doc.org/core-2.2.2/Marshal.html

from storext.

ramontayag avatar ramontayag commented on July 26, 2024 1

Ok that's right. Storext uses anonymous classes in which it defines Virtus attributes. The values go through an instance of that class and that instance that has Virtus does a lot of the typecasting/conversion. I'm not familiar with Marshal and don't really understand what it means when it says it will dump descendant objects.

from storext.

ramontayag avatar ramontayag commented on July 26, 2024 1

The fix might be somewhere here where marshal_dump and marshal_load are defined.

from storext.

topherfangio avatar topherfangio commented on July 26, 2024 1

So, the issue lies here:

def storext_proxy_class
  Storext.proxy_classes[self] ||= Class.new(*Storext.proxy_classes[self.superclass]) do
    include Virtus.model
    attribute :source
  end
end

Marshal.dump just doesn't know how to dump the Class.new.

We were able to monkey patch this with the following code.

module Storext
  module ClassMethods
    class Dumpable
      include Virtus.model
      attribute :source
    end
    
    def storext_proxy_class
      Storext.proxy_classes[self] ||= Dumpable
    end
  end
end

But I'm pretty sure this exists to cover cases of a parent class that uses Storext as well as it's child class using Storext, so this could easily break stuff for us later on down the road. Not sure if there is another workaround, but we couldn't figure out how to use the Marshal methods to get it working.

from storext.

ramontayag avatar ramontayag commented on July 26, 2024

@gcrofils when writing, Storext just uses ActiveRecord::Store underneath. Are you able to do what you want with ActiveRecord::Store?

For example, if you create a stored attribute but the value is nil, what happens?

from storext.

gcrofils avatar gcrofils commented on July 26, 2024

I don't fully understand your question "Are you able to do what you want with ActiveRecord::Store?".
In the previous example, if you remove Storext (include + store_attributes definition) from the class, without changing anything else. Marshal.dump works.

Regarding the second part of your message:

Marshal.dump fails if there is no value for an attribute with TypeError: can't dump anonymous class.
It works in other cases, either if there is a default value (defined in store_attributes) or a value set.
Hence if you try to Marshal.dump a record with a stored attribute that is nil, it will fail if this attribute has no default value.

from storext.

ramontayag avatar ramontayag commented on July 26, 2024

Thanks. This'll be helpful. Mind writing a failing test case? I'll see what I can do :)

from storext.

ramontayag avatar ramontayag commented on July 26, 2024

Right now all tests are failing in Travis, but you should be able to run it locally. I'm currently trying to fix the tests in Travis.

from storext.

ramontayag avatar ramontayag commented on July 26, 2024

@seattlecyclist will #56 work for you?

from storext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.