Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

object load bug? #76

Closed
Curter29 opened this Issue Mar 7, 2013 · 8 comments

Comments

Projects
None yet
2 participants

Curter29 commented Mar 7, 2013

open rails console

$cache = Memcached.new("localhost:11211")
$cache.set 'test', Oj.dump( Some ActiveRecord collection here )
Oj.load($cache.get 'test')

return right collection

exist console and open again and execute this code witout set

$cache = Memcached.new("localhost:11211")
Oj.load($cache.get 'test')

return nil element collection like [nil, nil ....]

Owner

ohler55 commented Mar 10, 2013

Can you check what the values are before going into Oj? Without knowing what is returned by Memcached there isn't much I can check.

I compare this strings on first session and second in AraxisMerge and they exactly same.

 2013-03-10 14 27 13

araxis merge 2 get result
 2013-03-10 14 52 50

Owner

ohler55 commented Mar 10, 2013

Instead of a screen shot can you send the text of the JSON so I can try to recreate the test?

From the output it looks like you might not have the Mark class loaded. If that is the case then setting then either make sure the Mark class is loaded or turn on the auto_define option in the default options of Oj

Oj.default_options = { :auto_define => true }

My fault, Oj.default_options = { :auto_define => true } resolve problem mostly.

"[{"^o":"Mark","attributes":{"id":"1","title":"Позитив"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"2","title":"Негатив"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"3","title":"Нейтрал"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"20","title":"Негатив-претензия"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"21","title":"негатив"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"22","title":"Нейтрал-консультация"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false},{"^o":"Mark","attributes":{"id":"23","title":"Негатив-консультация"},"relation":null,"changed_attributes":{},"previously_changed":{},"attributes_cache":{},"association_cache":{},"aggregation_cache":{},"marked_for_destruction":false,"destroyed":false,"readonly":false,"new_record":false}]"

parsed to

=> [#<Mark:0x007f854cad77c0 @attributes={"id"=>"1", "title"=>"Позитив"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cad6b68 @attributes={"id"=>"2", "title"=>"Негатив"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cad6550 @attributes={"id"=>"3", "title"=>"Нейтрал"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cad5ee8 @attributes={"id"=>"20", "title"=>"Негатив-претензия"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cad4d68 @attributes={"id"=>"21", "title"=>"негатив"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cadc6f8 @attributes={"id"=>"22", "title"=>"Нейтрал-консультация"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>, #<Mark:0x007f854cadbd70 @attributes={"id"=>"23", "title"=>"Негатив-консультация"}, @relation=nil, @changed_attributes={}, @previously_changed={}, @attributes_cache={}, @association_cache={}, @aggregation_cache={}, @marked_for_destruction=false, @DESTROYED=false, @readonly=false, @new_record=false>]

when { :auto_define => true }, but redefine Mark(ActiveRecord class), and i can't use Rails ActiveModel moethod on it.

Call Mark.all
NoMethodError: undefined method `all' for Mark:Class

I use load dump inside rails application, and models autoload when he need it. So when i try load dumped object, and have not load object class, they parsed to nil, nil.

This is no bug, but some unexpected behavior, in my point of view.

Owner

ohler55 commented Mar 10, 2013

The auto_define is for failing more gracefully when you forget to require a class or gem. The right answer is to require the missing gem or class. If you try and create a new Mark instance I suspect it will fail if you try it before doing the Oj.load(). Add a require for the gem that the Mark class is in and that should take care of the problem.

Thanks, for helping, sorry for this no bug -)

@Curter29 Curter29 closed this Mar 11, 2013

Owner

ohler55 commented Mar 11, 2013

I expect to get a few of those. Not a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment