neo4j-contrib/neomodel

Structured Node `__eq__` works incorrectly for non-persisted nodes.

OlehChyhyryn opened this issue · 0 comments

Expected Behavior (Mandatory)

If nodes are not created in the database and do not have an element_id property, they should be compared by id in memory or always count as different.

Actual Behavior (Mandatory)

All non-persisted node countries as equal

How to Reproduce the Problem

Create any StructuredNode objects without saving them to the database. Call comparison.

Simple Example

from neomodel import StructuredNode

class Foo(StructuredNode):
    pass

a = Foo()
b = Foo()

print(a == b)

The problem comes from the StructuredNode.__eq__ function.

    def __eq__(self, other):
        if not isinstance(other, (StructuredNode,)):
            return False
        if hasattr(self, "element_id") and hasattr(other, "element_id"):
            return self.element_id == other.element_id
        return False

I haven't prepared a pull request because I'm unsure which behavior should be selected as a default: all non-persisted nodes. Are they not equal, or do we want to compare them by memory ID or the other way around?

Screenshots (where it's possible)

Specifications (Mandatory)

Currently used versions

Versions

  • OS: WSL Ubuntu 22.04 + Windows 11
  • Library: 5.2.1
  • Neo4j: 5.16.0