neo4j-contrib / neomodel

An Object Graph Mapper (OGM) for the Neo4j graph database.
https://neomodel.readthedocs.io
MIT License
963 stars 232 forks source link

create_or_update does not call post_save #647

Open attilamester opened 2 years ago

attilamester commented 2 years ago

Hi! In neomodel==4.0.8, create_or_update does not call the post_save hook. Is this by design intended? Thanks!

a-takahashi223 commented 1 year ago

I ran the following code in 4.0.8.

class RelA(StructuredRel):
    def pre_save(self):
        print("relation pre_save")

    def post_save(self):
        print("relation post_save")

class NodeA(StructuredNode):
    b = RelationshipTo("NodeB", "SOME_REL", model=RelA)

    def pre_save(self):
        print("node pre_save")

    def post_save(self):
        print("node post_save")

    def pre_delete(self):
        print("node pre_delete")

    def post_delete(self):
        print("node post_delete")

    def post_create(self):
        print("node post_create")

class NodeB(StructuredNode):
    pass

a = NodeA().save()
a.b.connect(NodeB().save())
a.delete()

Output:

node pre_save
node post_create
node post_save
relation pre_save
relation post_save
node pre_delete
node post_delete

All hooks works well.

get_or_create() and create_or_update() do not invoke post_create. https://neomodel.readthedocs.io/en/latest/hooks.html

mariusconjeaud commented 1 year ago

Changed the title to your actual problem. Wouldn't know if this is by design, or something to add. Do you have an idea @a-takahashi223 ?

a-takahashi223 commented 1 year ago

I ran the test because the original title "Some hooks are only available using django_neomodel (pre_save, post_save, pre_delete, post_delete)" is concerned. I don't know about django_neomodel or create_or_update. Sorry.