Django

Code

Changeset 2047

Show
Ignore:
Timestamp:
01/18/06 07:16:58 (3 years ago)
Author:
russellm
Message:

magic-removal: Refs 1219 -- Added DELETE_ALL=True safety mechanism to prevent accidental deletion of entire table contents.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/manager.py

    r2039 r2047  
    101101        # Check if extra tables are allowed. If not, throw an error 
    102102        if (tables or joins) and not allow_joins: 
    103             raise TypeError("Joins are not allowed in this type of query") 
     103            raise TypeError, "Joins are not allowed in this type of query" 
    104104 
    105105        # Compose the join dictionary into SQL describing the joins. 
     
    151151 
    152152    def delete(self, *args, **kwargs): 
     153        nArguments = len(args) + len(kwargs) 
     154 
     155        # remove the DELETE_ALL argument, if it exists  
     156        delete_all = kwargs.pop('DELETE_ALL', False) 
     157 
    153158        # disable non-supported fields 
    154159        kwargs['select_related'] = False 
     
    158163        kwargs['limit'] = None 
    159164 
     165        # Check that there at least one query argument 
     166        if nArguments == 0 and not delete_all: 
     167            raise TypeError, "SAFTEY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data" 
     168                         
    160169        opts = self.klass._meta 
    161170 
  • django/branches/magic-removal/tests/modeltests/basic/models.py

    r2029 r2047  
    2112114L 
    212212 
     213>>> Article.objects.delete() 
     214Traceback (most recent call last): 
     215    ... 
     216TypeError: SAFTEY MECHANISM: Specify DELETE_ALL=True if you actually want to delete all data 
     217 
     218>>> Article.objects.delete(DELETE_ALL=True) 
     219>>> Article.objects.get_count() 
     2200L 
     221 
    213222""" 
    214223