From 69120fa9d3788438df9673ce107a752cb34a31a8 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 23 Jan 2006 02:34:07 +0000 Subject: [PATCH] magic-removal: Changed delete() safety-mechanism logic to happen as soon as possible. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2107 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/manager.py | 12 ++++++------ tests/modeltests/basic/models.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) 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()