diff --git a/django/db/models/manager.py b/django/db/models/manager.py index 52a4d67bd1..4a0892f38b 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -150,11 +150,15 @@ class Manager(object): return select, " ".join(sql), params def delete(self, *args, **kwargs): - nArguments = len(args) + len(kwargs) + num_args = len(args) + len(kwargs) - # remove the DELETE_ALL argument, if it exists + # Remove the DELETE_ALL argument, if it exists. delete_all = kwargs.pop('DELETE_ALL', False) + # Check for at least one query argument. + if num_args == 0 and not delete_all: + raise TypeError, "SAFETY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data." + # disable non-supported fields kwargs['select_related'] = False kwargs['select'] = {} @@ -162,10 +166,6 @@ class Manager(object): kwargs['offset'] = None kwargs['limit'] = None - # Check that there at least one query argument - if nArguments == 0 and not delete_all: - raise TypeError, "SAFTEY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data" - opts = self.klass._meta # Perform the SQL delete diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 1262217e08..aaba943d65 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -213,7 +213,7 @@ AttributeError: Manager isn't accessible via Article instances >>> Article.objects.delete() Traceback (most recent call last): ... -TypeError: SAFTEY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data +TypeError: SAFETY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data. >>> Article.objects.delete(DELETE_ALL=True) >>> Article.objects.get_count()