neomodel icon indicating copy to clipboard operation
neomodel copied to clipboard

pre_save hook for StructuredRel is broken

Open knivets opened this issue 4 years ago • 2 comments
trafficstars

If a user adds a hook to their StructuredRel subclass model with the intention of populating some fields before the node gets saved, it won't work. The hook will fire and it will run the code that updates the fields, however after the node is saved the database will contain the pre-hook stage values. The reason is that the node instance that is passed to the hook is discarded after the hook has executed, I traced this problem to this code chunk. The params dict would hold the pre-hook stage values, and there is no way to influence this process for inside the hook.

I think being able to modify the actual object within a hook is important. I used a pre_save hook so I could implement the updated_at property that is updated each time an object is saved.

knivets avatar Mar 17 '21 13:03 knivets

Hey! Are there any plans to fix this?

knivets avatar Jul 14 '21 14:07 knivets

Hey @knivets we do plan to fix it, we are just limited in resources. I put this issue at the top of our 'to do' here:

https://github.com/neo4j-contrib/neomodel/projects/1

whatSocks avatar Jul 14 '21 15:07 whatSocks