activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

has_n results get mixed up if objects in previous result are == to each other

Open yourpalal opened this issue 5 years ago • 0 comments

Additional information which could be helpful if relevant to your issue:

This came up in our code because we have a model which uses a custom ID key, but we forgot to set the id_property. Neo4j is expecting the id to be uuid and most of the time that was fine, but a few of these objects were created outside of neo4j and therefore have no uuid property. When they're compared with ==, the result is true even though they have different neo_ids, etc.

Code example (inline, gist, or repo)

a, b, c = three_neo4j_objects()
assert b == c

a.friends = [b]
b.friends = [a]
c.friends = []

a, b, c = Things.all.where(custom_id: [a,b,c].map(&:custom_id)).to_a
# (assume they come out in the right order)

a.friends # this causes association_proxy to load the association for all of a, b, and c
assert_length 1, a.friends # OK
assert_length 1, b.friends # fails - b got the query proxy of c because it came after b in the results and they are == to each other
assert_length 0, c.friends # OK

Seems kinda random, but this issue is easy to avoid and it's not totally impossible that someone might do what I did (end up with uuid: nil on multiple models) or override == in a way that messes up the query.

Runtime information:

neo4j gem version: 8.1.5, but I have confirmed that the code has this issue in master HEAD

yourpalal avatar Nov 29 '18 20:11 yourpalal