Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apoc.trigger deletedNodes should return all properties for the node #720

Closed
abccbaandy opened this issue Jan 24, 2025 · 3 comments
Closed

Comments

@abccbaandy
Copy link

Guidelines

Please note that GitHub issues are only meant for bug reports/feature requests. If you have questions on how to use APOC, please ask on the Neo4j Discussion Forum instead of creating an issue here.

Expected Behavior (Mandatory)

deletedNodes should return all properties for the node

Actual Behavior (Mandatory)

deletedNodes return empty properties map, with negative element id

How to Reproduce the Problem

Simple Dataset (where it's possibile)

//Insert here a set of Cypher statements that helps us to reproduce the problem
CREATE(n:SomeNew {uuid:"2d3d53e5-352f-4d2b-bbbe-656b4bcc2b34"})

Steps (Mandatory)

  1. add trigger
:use system;
CALL apoc.trigger.install(
  'neo4j',
  'add delete node log',
  '
      UNWIND $deletedNodes as n
      WITH n
      WHERE NOT "Log" in labels(n)
      CREATE (log:Log)
      SET 
	  log.data=apoc.convert.toJson(properties(n)), 
	  log.nodeId = elementId(n)
  ',    
  {phase:'afterAsync'}
);
  1. delete the node
MATCH(n:SomeNew {uuid:"2d3d53e5-352f-4d2b-bbbe-656b4bcc2b34"})
DELETE n
  1. query the log node
MATCH(n:Log)
RETURN n

Screenshots (where it's possibile)

The result

data | {} |
nodeId | -2

Specifications (Mandatory)

Currently used versions

Versions

  • OS: Window
  • Neo4j: 5.26.1
  • Neo4j-Apoc: 5.26.1
@gem-neo4j
Copy link
Contributor

gem-neo4j commented Jan 31, 2025

Hi there!

Thanks for writing in :) The triggers reference Virtual Nodes and Relationships which means the properties function doesn't work on it, try updating you query to use apoc.any.properties(n) instead:

:use system;
CALL apoc.trigger.install(
  'neo4j',
  'add delete node log',
  '
      UNWIND $deletedNodes as n
      WITH n
      WHERE NOT "Log" in labels(n)
      CREATE (log:Log)
      SET 
	  log.data=apoc.convert.toJson(apoc.any.properties(n)), 
	  log.nodeId = elementId(n)
  ',    
  {phase:'afterAsync'}
);

The element id is not supported yet for the way these virtual nodes are created, so that is a bug, I will create a ticket for this part.

I see the documentation is lacking any information about this limitation so will make a ticket for my team to fix up. Let me know if this solves your issue! Thanks :D

@abccbaandy
Copy link
Author

Thanks, the apoc.any.properties way works.

I think it's better throw exception if a function does not work with vNode or it's very error prone.

@gem-neo4j
Copy link
Contributor

Yep, unfortunately the error part would actually need to be implemented on the Neo4j side. There is a card someone else made who had encountered a similar issue so that may one day be fixed.

We have updated the docs now too, so I will close this :) Thanks for writing in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants