yeti icon indicating copy to clipboard operation
yeti copied to clipboard

Remove references to observable when it is deleted

Open tomchop opened this issue 8 years ago • 1 comments
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

  1. Add two Observables to the database
  2. Create an investigation, add the two observables to it
  3. Delete one of the nodes from the database or via mongoengine's delete() function
  4. 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.

tomchop avatar Nov 01 '17 19:11 tomchop

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?

doomedraven avatar May 25 '19 21:05 doomedraven