0

We're using a jRuby on Rails with Neo4j, and we're getting some very odd errors. Currently, we have users able to create posts. Very rarely, it seems that they get unwrapped nodes in their "posts" relationships instead of Post objects. For example, in console, I iterated over one user's posts, and this is what it came up:

> user.posts.each{ |post| puts post }
#<Post:0x49ca112d>
#<Post:0xc9ddbea>
#<Post:0x7e706c75>
Node[438144]
#<Post:0x769dba83>

This is causing all sorts of problems, as we get errors like this whenever we try to access a property or relationship of one of these non-post posts:

undefined method `[any property or relationship]' for #<Java::OrgNeo4jKernelImplCore::NodeProxy:0x461784b6>

These naked nodes seem to be getting added to people's "post" relationships intermittently, and I can manually delete the node, but this seems to be only a stop-gap measure at best because they keep being created.

So, my question is, how do I (1) prevent these non-Post objects from being created in the first place, and how do I (2) purge my database of these objects?

jwest
  • 342
  • 3
  • 10

1 Answers1

1

One reason for this behaviour could be that you use protected_keys when updating a node ( when just using the neo4j-wrapper gem).

I suspect that the _classname property for some reason has disappeared (which could happen using the protected_keys conf, see the github issue below). E.g. you have added a post to the user post relationships which is not a post (it does not have the _classname property with value 'Post').

Example, if you do something like this you will have this problem:

user.posts << Neo4j::Node.new

I would recommend some debugging in order to make sure that all your post objects have a _classname property.

If it's a bug in neo4j.rb you can do the following ugly workaround to load the wrapped objects.

user.posts.map{|p| p.wrapper}.each{ |post| puts post }

I've added an github issues just in case for this, https://github.com/andreasronge/neo4j/issues/230 Please add more information how I could reproduce it, e.g. versions of neo4j and jruby. A test case would also be very handy.

Andreas Ronge
  • 321
  • 1
  • 4