Can we validate links after specific hooks? such as "before_insert"?

I am building a some event driven logic and one of those is to create a Role Profile if it does not exists, so I added a method in hooks.py > User< before_insert but it was throwing an error saying that link does not exists.

After seeing the logic turns out the code validates links before running hooks.

Would that be possible to move after certain hook? I know I can pass ignore_links, but I do not want to do that, since I want ot make sure that it validates the links. Running doc._validate_links() defeats the purpose.

try using before_validate or before_save method

I tried. _validate_links() happens before hooks.

# code
self._validate_links() # Error in thrown here
self.check_permission("create")
self.run_method("before_insert")

# code happens here

self.run_before_save_methods() # `before_validate` is triggered here
self._validate()

I have linked the code flow above.

Do one thing: pass ignore_links as an argument and manually call self._validate_links() afterward. Then it will validate the links.
and use database transactions; if anything fails, the transaction will be rolled back.

That works and I have mentioned above.

That’s what I’m saying: call the self._validate_links() function manually in your code, so it will also validate the links. :smile: