Neo4j 5: CALL subquery without a variable scope clause is now deprecated
Description:
What issue is being seen? Describe what should be happening instead of the bug, for example: Cartography should not crash, the expected value isn't returned, the data schema is wrong, etc.
Run Cartography 0.101.0rc1 against Neo4j Aura.
Not a crash or a bug, but we should plan to upgrade the syntax here.
To Reproduce:
Steps to reproduce the behavior. Provide all data and inputs required to reproduce the issue.
Logs:
If applicable, copy and paste your console log with the failing stack trace.
Example run
WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.FeatureDeprecationWarning} {category: DEPRECATION} {title: This feature is deprecated and will be removed in future versions.} {description: CALL subquery without a variable scope clause is now deprecated.
Use CALL (i, item) { ... }} {position: line: 16, column: 9, offset: 459}
for query: '
UNWIND $DictList AS item
MERGE (i:KandjiDevice{id: item.id})
ON CREATE SET i.firstseen = timestamp()
SET
i.lastupdated = $lastupdated,
i.device_id = item.device_id,
i.device_name = item.device_name,
i.last_check_in = item.last_check_in,
i.model = item.model,
i.os_version = item.os_version,
i.platform = item.platform,
i.serial_number = item.serial_number
WITH i, item
CALL {
WITH i, item
OPTIONAL MATCH (j:KandjiTenant{id: $TENANT_ID})
WITH i, item, j WHERE j IS NOT NULL
MERGE (i)-[r:ENROLLED_TO]->(j)
ON CREATE SET r.firstseen = timestamp()
SET
r.lastupdated = $lastupdated
}
Please complete the following information::
- Cartography release version or commit hash [e.g. 0.12.0 or 95e8e11913e2a44a4d4682506d8364a638ceac69] 0.101.0rc1
Hello @achantavy I am new to this project and want to work on this I understand the issue - Neo4j 5 requires explicit variable scoping in CALL subqueries instead of the current pattern of using WITH clauses inside subqueries. My approach would be to:
- Locate all instances of CALL { in the codebase (likely in .json files and .py files that construct queries)
- For each instance, identify which variables are passed from the outer scope to the subquery
- Replace the pattern as you have described
- Write tests to verify the updated queries work correctly I would be happy to work on this, also is my approach good?
Hey thanks for your interest and thanks for offering to help.
Locate all instances of CALL { in the codebase (likely in .json files and .py files that construct queries)
It's specifically it's these sections:
https://github.com/cartography-cncf/cartography/blob/52eef1bd32cbf34668ba0f2dccaecf6238120fb4/cartography/graph/querybuilder.py#L356-L362
https://github.com/cartography-cncf/cartography/blob/52eef1bd32cbf34668ba0f2dccaecf6238120fb4/cartography/graph/querybuilder.py#L356-L366
Tests like this would need to be updated: https://github.com/cartography-cncf/cartography/blob/52eef1bd32cbf34668ba0f2dccaecf6238120fb4/tests/unit/cartography/graph/test_querybuilder_complex.py#L10
The tricky part is updating the syntax here would make the warning message go away on Neo4j 5, but if I understand correctly it would make Neo4j 4 stop working altogether. We would only be able to make the update when we are fully ready to commit to version 5. Version 4 will be EOL in November 2025: https://neo4j.com/developer/kb/neo4j-supported-versions/#_neo4j_database_enterprise_edition_4.
So for now if we do nothing, version 5 users get warning messages, but if we change it then cartography will stop working for version 4 users. Since there are 6 months left until the EOL time, we can wait a bit until we communicate the deprecation of version 4.
I also don't want to introduce complicated `if neo is this version then generate this, but if neo is that version then generate that' logic to have things running side by side. So, I'd say let's hold off. Side note: how'd you find this project and what are you using it for? Would love to learn more, feel free to join our slack :). If you're looking for other issues to work on, would super appreciate help adding more intel modules.
@heryxpc - have you guys migrated to neo4j 5 yet?
Hello @achantavy I'm a student learning graph databases. I found Cartography while researching tools that visualize cloud infrastructure relationships, also I am proficient with python so thought of making few contributions to make myself familiar with the codebase.
Also, for this particular issue I agree with you to hold of this as this may create some unnecessary issues for the users
I would like to help in adding more intel modules, would be grateful if you give some particular advice on it.
@AdityaPandeyCN - Awesome! You can look at https://github.com/cartography-cncf/cartography/issues/1477 or https://github.com/cartography-cncf/cartography/issues/1552.
You can follow the dev docs here: https://cartography-cncf.github.io/cartography/dev/writing-intel-modules.html
If using AI for vibe-coding, follow these tips: https://github.com/cartography-cncf/cartography/pull/1508#issuecomment-2810882674
@AdityaPandeyCN feel free to join US on Slack if you need help to jump into it.