neomodel
neomodel copied to clipboard
order_by internal id doesn't work
The order_by currently only works for properties defined by the user. I think ordering by the internal id from Neo4j should also be possible.
The problem lies here:
https://github.com/neo4j-contrib/neomodel/blob/9c405aa5b75cbf3e2612ba0605b25996ba607e2d/neomodel/match.py#L197-L198
defined_properties only returns user-defined properties, so specifying id as an argument for order_by throws the ValueError.
If this is prohibited on purpose for some reason, the error message should read something like No such user-defined property. If it's not on purpose, this would be an easy fix, I guess:
if prop != "id" and prop not in cls.defined_properties(rels=False):
raise ValueError("No such property {0} on {1}".format(prop, cls.__name__))
Hi @j-kuehn , Usually the internal id is for internal use and people are encouraged to use their own domain-specific ids. We could improve the error message though, to make this more explicit
See release 5.1.2
I chose to make this prohibited because Neo4j internals are intended for use by Neo4j only. For example, they can technically change over time (if you delete then re-create a node, or clone it), and across servers in a cluster. So you shouldn't rely on them.
It is still technically possible to order / filter on them by using plain Cypher.