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

Added random postfix to the ref variable, to avoid reserve words collision #782

Closed yackermann closed 3 months ago

yackermann commented 7 months ago

The issue I had is that my Node class was name Case. When label is generated it is using lower case class name, so it was using case as variable

MATCH (case) WHERE elementId(case)=$case_1 WITH case MATCH (case)-[r1:`PARTICIPATES`]-(participants_r1:Applicant) RETURN participants_r1

that line

MATCH (case) is interpreted by CQL as MATCH (CASE).

So I've added random prefix to the variables and labels to prevent accidental reserve words panics in future

This is a result query:

MATCH (case_3023) WHERE elementId(case_3023)=$case_3023_1 WITH case_3023 MATCH (case_3023)-[r1:`PARTICIPATES`]-(participants_r1:Applicant) RETURN participants_r1
sonarcloud[bot] commented 7 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

mariusconjeaud commented 4 months ago

This breaks tests, and especially breaks the fetch_relations with filter() applied (see test_match_api.py::test_fetch_relations). In this example, it creates queries like - notice how the variable name for the first node of the MATCH is different than the one in the WHERE clause, because it's creating a random suffix for both :

MATCH (supplier_1ab2:Supplier)-[r1:COFFEE_SUPPLIERS]->(coffee_coffees_1:Coffee)-[r2:COFFEE_SPECIES]->(species_species_1:Species) WHERE supplier_23te.name = $supplier_name_1 RETURN supplier, coffee_coffees_1, r1, species_species_1, r2