Skip to content
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

Incorrect hash for bound nodes with identity=0 #942

Open
atsysin opened this issue Apr 30, 2022 · 0 comments
Open

Incorrect hash for bound nodes with identity=0 #942

atsysin opened this issue Apr 30, 2022 · 0 comments

Comments

@atsysin
Copy link

atsysin commented Apr 30, 2022

Expected behavior

For bound nodes with identity=0, hash computation should be based on the graph.service, graph.name and identity attributes.

Actual behavior

If identity=0 for a bound node, then the if statement on line 691 is equivalent to the snippet below and always evaluates to False:

if self.graph and 0:
    ...

which means that the hash is computed based on the Python object's identity.

Steps to reproduce the problem

You would need a fresh Neo4j instance, or to query a node with <id>: 0, or to set node's identity to 0 manually:

from py2neo import Graph, Node

g = Graph()
n = Node()
g.create(n)  # node is bound now
n.identity = 0  # re-write identity for demonstration
h = hash(n)

h_unbound = hash(id(n))
print(h == h_unbound)

h_bound = hash(n.graph.service) ^ hash(n.graph.name) ^ hash(n.identity)
print(h == h_bound)

Proposed solution

Replace the line 691 with

if self.graph and (self.identity is not None):
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant