From d21434dfd648332f903b0ebe99d10197f740ce03 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sun, 5 Dec 2010 22:40:01 -0800 Subject: [PATCH] Make the nullification an atomic operation. This shortcut works now, since hmarr fixed the unset bug in dev. --- mongoengine/document.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/mongoengine/document.py b/mongoengine/document.py index 3b812abb..39442f6f 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -106,18 +106,7 @@ class Document(BaseDocument): if rule == CASCADE: document_cls.objects(**{field_name: self.id}).delete(safe=safe) elif rule == NULLIFY: - # TODO: For now, this makes the nullify test pass, but it would - # be nicer to use any of these two atomic versions: - # - # document_cls.objects(**{field_name: self.id}).update(**{'unset__%s' % field_name: 1}) - # or - # document_cls.objects(**{field_name: self.id}).update(**{'set__%s' % field_name: None}) - # - # However, I'm getting ValidationError: 1/None is not a valid ObjectId - # Anybody got a clue? - for doc in document_cls.objects(**{field_name: self.id}): - doc.reviewer = None - doc.save() + document_cls.objects(**{field_name: self.id}).update(**{'unset__%s' % field_name: 1}) id_field = self._meta['id_field'] object_id = self._fields[id_field].to_mongo(self[id_field])