-
Notifications
You must be signed in to change notification settings - Fork 55
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
Can't dump anonymous class if default value not set. #47
Comments
@gcrofils when writing, Storext just uses For example, if you create a stored attribute but the value is nil, what happens? |
I don't fully understand your question "Are you able to do what you want with Regarding the second part of your message:
|
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 |
The fix might be somewhere here where |
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
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 |
Thanks. This'll be helpful. Mind writing a failing test case? I'll see what I can do :) |
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. |
@ramontayag - With regard to the error @topherfangio reported. I work with him. Here is a failing spec. Just drop it into your
/edit Marshal.dump is used by memcache when you try to cache an object. So this use case is 'common' IMHO.
Edit 2/ Docs on the Marshal.dump method https://ruby-doc.org/core-2.2.2/Marshal.html |
@seattlecyclist will #56 work for you? |
Summary
Marshal.dump
fails on any object if default value is not defined for Jsonb attributesSteps to replicate
rails new storext-demo --api
pg
gem, addstorext
gemrails g model book title:string data:jsonb
rails g model post title:string data:jsonb
Marshal.dump
works on model with default valueBook.create title:'Lorem Ipsum'
Marshal.dump Book.first
==> OKMarshal.dump
fails on model without default valuePost.create title:'Lorem Ipsum'
Marshal.dump Post.first
==> KOTypeError: can't dump anonymous class #<Class:0x007fefcdab1340>
The text was updated successfully, but these errors were encountered: