niho / related

A high performance distributed graph database.
MIT License
130 stars 13 forks source link

Inconsistent object deserialization #15

Closed plukevdh closed 10 years ago

plukevdh commented 11 years ago

Using two different methods to query for an object returns slightly different reinstantiations of a record:

2.0.0 :002 > cam.outgoing(:changesets).options(model: TFSGraph::Changeset).nodes.to_a.first
 => #<TFSGraph::Changeset:0x007fd0facd66f8 @attributes={"comment"=>"...", "committer"=>"...", "created"=>2013-09-20 14:07:49 -0400, "branch"=>"...", "tags"=>"[]", "parent"=>0, "merge_parent"=>0, "created_at"=>"2013-10-07T21:04:02Z", "updated_at"=>"2013-10-07T21:04:02Z"}, @_internal_id="nhAgogz8xw1lpBG5hNqBWQ", @id="213">

2.0.0 :003 > TFSGraph::Changeset.find(213)
 => #<TFSGraph::Changeset:0x007fd0facf5f08 @attributes={"comment"=>"...", "committer"=>"...", "created"=>2013-09-20 14:07:49 -0400, "branch"=>"...", "tags"=>"[]", "parent"=>0, "merge_parent"=>0, "created_at"=>"2013-10-07T21:04:02Z", "updated_at"=>"2013-10-07T21:04:02Z"}, @_internal_id="sDOjrqDq8nBQMEeJyg5uSA", @id=213>

Note the id, parent and merge parent are all strings using the #find_many method while #find_one deserializes properly. The model definition is as follows:

module TFSGraph
  class Changeset < Entity

      property :comment, String
      property :committer, String
      property :created, DateTime
      property :id, Integer
      property :branch, String
      property :tags, Array
      property :parent, Integer
      property :merge_parent, Integer
plukevdh commented 11 years ago

I'm looking into a fix for this, but my assumption right now is that Entity#load_attributes does not take into account the deserialization of the attributes like #initialize does.

plukevdh commented 11 years ago

Also doesn't appear to be deserializing DateTime for created_at or updated_at back from a string in either case.

plukevdh commented 11 years ago

Note, this is based off of the branch used for PR #13. Recommend pulling in that one first if desired.

plukevdh commented 11 years ago

Hm, this does cause a problem with deserializing properties with blocks...

plukevdh commented 10 years ago

I dislike this idea in the end. I do think serialization/deserialization may need to be made more consistent, but I'm not sure this is the solution...