#10304: topics/db/queries.txt about delete() lies!
---------------------------------------------------+------------------------
          Reporter:  telenieko                     |         Owner:  nobody
            Status:  closed                        |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.0   
        Resolution:  invalid                       |      Keywords:  delete
             Stage:  Unreviewed                    |     Has_patch:  0     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by kmtracey):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => invalid
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I haven't looked at the !QuerySet code but a little shell experimentation
 shows that it is not impossible to avoid calling delete() of every single
 object.  Given this model:

 {{{
 #!python
 class DT(models.Model):
     name = models.CharField(max_length=5)

     def delete(self):
         print 'Delete for %s called' % self.name
         super(DT, self).delete()

     def __unicode__(self):
         return self.name
 }}}

 and this shell session:

 {{{
 Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
 [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 (InteractiveConsole)
 >>> import django
 >>> django.get_version()
 u'1.1 pre-alpha SVN-9841'
 >>> from ttt.models import DT
 >>> DT.objects.create(name='x')
 <DT: x>
 >>> DT.objects.create(name='y')
 <DT: y>
 >>> DT.objects.create(name='z')
 <DT: z>
 >>> DT.objects.all()
 [<DT: x>, <DT: y>, <DT: z>]
 >>> x = DT.objects.all()[0]
 >>> x.delete()
 Delete for x called
 >>> DT.objects.all()
 [<DT: y>, <DT: z>]
 >>> DT.objects.all().delete()
 >>> DT.objects.all()
 []
 >>>

 }}}

 The individual delete() method was not called for
 `DT.objects.all().delete()`.

 (Even if it was the case that the code as written now always guaranteed
 the individual delete() methods were called, the doc would not be wrong.
 It is warning that the individual delete() may not be called when objects
 are deleted in bulk, it doesn't say it absolutely will not be called.)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10304#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to