mwdb-core
mwdb-core copied to clipboard
Hook inconsistency - on_created_tag not triggered for reuploaded objects
Environment information
- MWDB version (from
/about): v2.14.0 - Installation method:
- [ ] mwdb.cert.pl service
- [ ] From PyPi (
pip install mwdb-core) - [x] From docker-compose
- [ ] Other (please explain)
- Plugins installed:
Behaviour the bug (what happened?)
on_created_tag is triggered during object upload only if object is new. If object upload was requested along with some new tags but object already exists, on_created_tag is not triggered for these new tags that are appended to the object.
Expected behaviour
on_created_tag should be triggered every time tag is added to the object.
Actually supported hook list is pretty broad but they're triggered only in oddly specific cases e.g. on_created_attribute is triggered only in attribute was added by calling POST /api/{type}/{hash}/attribute.
Current implementation is based on direct calls of hook dispatchers inside endpoint handling methods. I think better implementation would be a list of actions collected in e.g. g.request_actions. Every time we add tag using mwdb.model.object.Object.add_tag, proper actions are added to the queue.
Finally, actions are iterated using dedicated hook dispatcher method, where proper hooks are called depending on the action. Hook dispatcher method should be called at the end of the request handling, after transaction was committed. Failed hook call should not result in ISE 500 although proper error should be logged (non-fatal errors handling is also a problem there: https://github.com/CERT-Polska/mwdb-core/issues/891)