neomodel icon indicating copy to clipboard operation
neomodel copied to clipboard

order_by internal id doesn't work

Open j-kuehn opened this issue 4 years ago • 1 comments
trafficstars

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__))

j-kuehn avatar Jun 24 '21 14:06 j-kuehn

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

whatSocks avatar Jul 02 '21 01:07 whatSocks

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.

mariusconjeaud avatar Sep 26 '23 13:09 mariusconjeaud