diff --git a/docs/changelog.rst b/docs/changelog.rst index 18b94d3d..5baa761b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in dev ============== +- Error raised if update doesn't have an operation - DeReferencing is now thread safe - Errors raised if trying to perform a join in a query - Updates can now take __raw__ queries diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 0b73b87d..ade5279a 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -1332,11 +1332,14 @@ class QuerySet(object): key = '.'.join(parts) + if not op: + raise InvalidQueryError("Updates must supply an operation eg: set__FIELD=value") + if op: value = {key: value} key = '$' + op - if op is None or key not in mongo_update: + if key not in mongo_update: mongo_update[key] = value elif key in mongo_update and isinstance(mongo_update[key], dict): mongo_update[key].update(value) diff --git a/tests/document.py b/tests/document.py index 35734027..252393cf 100644 --- a/tests/document.py +++ b/tests/document.py @@ -1432,6 +1432,12 @@ class DocumentTest(unittest.TestCase): self.assertRaises(OperationError, update_no_value_raises) + def update_no_op_raises(): + person = self.Person.objects.first() + person.update(name="Dan") + + self.assertRaises(InvalidQueryError, update_no_op_raises) + def test_embedded_update(self): """ Test update on `EmbeddedDocumentField` fields