#9023: OneToOneField delete() problem
------------------------------------------+---------------------------------
 Reporter:  TheShark                      |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Uncategorized                 |     Version:  1.0       
 Keywords:  OneToOneField delete cascade  |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 Accessing the automatic reverse relationship on an instance (w.sprocket in
 the following example) causes some type of caching to happen which results
 in my Sprocket getting caught up in a cascade delete() of a Widget
 erroneously. The following example works without the print statement, and
 my Sprocket s exists at the end. If I 'print w.sprocket' before clearing
 the relationship, my Sprocket gets deleted along with my Widget when it
 shouldn't.

 {{{
 class Widget(models.Model):
     name = models.CharField(max_length=10)

     def __unicode__(self):
         return u'%s(%s)'%(self.name,self.pk)

 class Sprocket(models.Model):
     name = models.CharField(max_length=10)
     w = models.OneToOneField(Widget, null=True, blank=True)

     def __unicode__(self):
         return u'%s(%s)'%(self.name,self.pk)

 And the following sequence of operations:

 w=Widget(name="Some Widget")
 w.save()
 s=Sprocket(name="Some Sprocket")
 s.w=w
 s.save()

 assert Widget.objects.all().count()==1
 assert Sprocket.objects.all().count()==1

 #print w.sprocket
 s.w=None
 s.save()
 w.delete()

 assert Widget.objects.all().count()==0
 assert Sprocket.objects.all().count()==1
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9023>
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to