yeti
yeti copied to clipboard
Remove references to observable when it is deleted
trafficstars
Description
Investigations contain empty DBRefs when an observable is deleted from the database, provoking all kinds of problems.
Environment
| Question | Answer |
|---|---|
| Git commit | 06aa4ddd4bb3b9efba740d33e52073fb5cb51c9a |
| OS version | 10.12.6 |
| Browser | Chrome 61.0.3163.100 |
Steps to Reproduce
- Add two Observables to the database
- Create an investigation, add the two observables to it
- Delete one of the nodes from the database or via mongoengine's
delete()function - Try to load the investigation
Expected behavior
Investigation and nodes load
Actual behavior
Investigation doesn't load, request 500's. In core/investigation.py L63, it complains about one of the nodes not having a to_mongo attribute.
I think this can be fixed by adding a delete rule in the Investigation model definition, but I'll leave this up to you in case you want to take any other actions on the investigation itself.
Tried to dig into this and make it working, but it doesn't work and can't make it working
i have tried different variations
nodes = ListField(ReferenceField('Node', dbref=True, reverse_delete_rule=PULL))
nodes = ListField(ReferenceField('Node', dbref=True, reverse_delete_rule=NULLIFY))
nodes = ListField(ReferenceField('Node', dbref=True), reverse_delete_rule=PULL)
nodes = ListField(ReferenceField('Node', dbref=True), reverse_delete_rule=NULLIFY)
nodes = ListField(ReferenceField('Node', dbref=True), reverse_delete_rule=CASCADE)
in database.py
class Node(YetiDocument):
exclude_fields = ['attached_files']
attached_files = ListField(
ReferenceField(AttachedFile, reverse_delete_rule=PULL))
any idea?