neo4j-contrib / neomodel

An Object Graph Mapper (OGM) for the Neo4j graph database.
https://neomodel.readthedocs.io
MIT License
936 stars 231 forks source link

AttributeError: 'SpecificNode' object has no attribute 'unique_relation' #773

Closed u3Izx9ql7vW4 closed 8 months ago

u3Izx9ql7vW4 commented 8 months ago

Update: I tried implementing a custom StructuredRel and having a string field as the relationship type. This appears to work except if I don't call save() on the model before I call connect(), it will give an error:

File [/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:133](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:133), in RelationshipManager.connect(self, node, properties)
    [130](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:130)     self.source.cypher(q, params)
    [131](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:131)     return True
--> [133](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:133) rel_ = self.source.cypher(q + " RETURN r", params)[0][0][0]
    [134](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:134) rel_instance = self._set_start_end_cls(rel_model.inflate(rel_), node)
    [136](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/neomodel/relationship_manager.py:136) if hasattr(rel_instance, "post_save"):

IndexError: list index out of range

This error does not appear if I don't specify the model field in RelationshipTo.

Expected Behavior (Mandatory)

Be able to use relationship defined in subclass. i.e. I have a Node class and various subclasses of Node which has additional relationships but share common properties with the parent class.

Actual Behavior (Mandatory)

Gives error: AttributeError: 'SpecificNode' object has no attribute 'unique_relation'

How to Reproduce the Problem

class Node(StructuredNode):
    uid          = StringProperty(unique_index=True, required=True)
    family      = StringProperty(index=True, required=True)
    layer        = StringProperty(index=True, required=True)
    generic_relation = RelationshipTo('Node', 'DEPENDS_ON')

class SpecificNode(Node):
    unique_relation = RelationshipTo('SpecificNode', 'IS_FROM')

# ... some code to instantiate these
othernode = SpecificNode( ... )
mynode = SpecificNode( ... )
mynode.unique_relation.connect(other_node)

The last line gives: AttributeError: 'SpecificNode' object has no attribute 'unique_relation'

Versions

krashr-ds commented 8 months ago

I have this same problem.

u3Izx9ql7vW4 commented 8 months ago

Issue was caused by use of semi-colon instead of equals sign in the class definition. Calling save() function appears to be a different problem. I'm closing the issue.