mirror of
https://github.com/django/django.git
synced 2025-06-04 19:19:13 +00:00
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
This commit is contained in:
parent
25e1e1392f
commit
69120fa9d3
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user