2

I'm working with the interface py2neo to access the neo4j database out of python. I want to used the autogenerated Id column in an OGM model as a property. But my idea doesn't work. Please look a the example:

from py2neo import Graph, Node, Relationship
from py2neo.ogm import GraphObject, Property, RelatedTo, RelatedFrom

class Material(GraphObject):
    id = Property()
    name = Property()
    description = Property()

I insert the values into the system:

mat_f01 = Node('Material', name='F01', description='Fert Product 01')
mat_f02 = Node('Material', name='F02', description='Fert Product 02')

In the neo4j browser the record are displayed as followed - with the id column:

<id>:178 description: Fert Product 02 name: F02 

If I look to the same records in flask the Id column contains the value None. It should contain 177 and 178.

description             id      name
Fert Product 01 Fert    None    F01 
Fert Product 03 Fert    None    F03

Many thanks in advance.

Ralf
  • 21
  • 1

1 Answers1

1

The node ID has no correlation with the properties on that node. It is more of an internal attribute, closer to the address of a variable than an auto-generated ID. It is exposed by Neo4j as a convenience but should not be used for anything that requires a stable node reference as it can't provide those guarantees of stability.

If you want a unique identifier property then I recommend a UUID4 hex string instead. You can generate one of these in Python via the uuid module, and it should be guaranteed unique for all practical purposes.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15