[Django] #12166: Instance.delete() cascade deletes related objects with null=True

View: New views
4 Messages — Rating Filter:   Alert me  

[Django] #12166: Instance.delete() cascade deletes related objects with null=True

by noreply-71 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12166: Instance.delete() cascade deletes related objects with null=True
---------------------------+------------------------------------------------
 Reporter:  oremj          |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Uncategorized  |     Version:  1.1      
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 Server model relation:
   {{{ server_model = models.ForeignKey('ServerModel', blank=True,
 null=True) }}}

 {{{
 a = System.objects.all()[0]
 b = ServerModels.objects.all()[0]

 b.delete()
 }}}
 Both b and a are deleted.

 db.connection.queries:
 {{{
  {'sql': u'SELECT `systems`.`id`, `systems`.`hostname`,
 `systems`.`serial`, `systems`.`operating_system_id`,
 `systems`.`server_model_id`, `systems`.`created_on`,
 `systems`.`updated_on`, `systems`.`oob_ip`, `systems`.`asset_tag`,
 `systems`.`notes`, `systems`.`licenses`, `systems`.`allocation_id`,
 `systems`.`system_rack_id`, `systems`.`rack_order`,
 `systems`.`switch_ports`, `systems`.`patch_panel_port`,
 `systems`.`oob_switch_port`, `systems`.`purchase_date`,
 `systems`.`purchase_price`, `systems`.`system_status_id`,
 `systems`.`change_password`, `systems`.`ram` FROM `systems` WHERE
 `systems`.`server_model_id` = 221 ',
  {'sql': u'UPDATE `systems` SET `server_model_id` = NULL WHERE `id` IN
 (1333)',
  {'sql': u'DELETE FROM `systems` WHERE `id` IN (1333)'},
  {'sql': u'DELETE FROM `server_models` WHERE `id` IN (221)'}]

 }}}

 I'm not seeing this problem on 1.1, but I am seeing it on 1.1.1 and later.

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


Re: [Django] #12166: Instance.delete() cascade deletes related objects with null=True

by noreply-71 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12166: Instance.delete() cascade deletes related objects with null=True
------------------------------------+---------------------------------------
          Reporter:  oremj          |         Owner:  nobody
            Status:  new            |     Milestone:        
         Component:  Uncategorized  |       Version:  1.1  
        Resolution:                 |      Keywords:        
             Stage:  Unreviewed     |     Has_patch:  0    
        Needs_docs:  0              |   Needs_tests:  0    
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by oremj):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 Nevermind, this also happens on 1.1.

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


Re: [Django] #12166: Instance.delete() cascade deletes related objects with null=True

by noreply-71 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12166: Instance.delete() cascade deletes related objects with null=True
------------------------------------+---------------------------------------
          Reporter:  oremj          |         Owner:  nobody
            Status:  new            |     Milestone:        
         Component:  Uncategorized  |       Version:  1.1  
        Resolution:                 |      Keywords:        
             Stage:  Unreviewed     |     Has_patch:  0    
        Needs_docs:  0              |   Needs_tests:  0    
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Comment (by Suor):

 Having the same problem with:

 {{{
 class Blog(models.Model):
     ...
     last_comment = models.ForeignKey('BlogComment', blank = True, null =
 True, editable = False)

 class BlogComment(CommonComment):
     blog = models.ForeignKey(Blog)
 }}}

 When deleting last comment the whole blog is deleted. Django should be
 able to behave in 'on delete set null' style.
 Having this on 1.1

--
Ticket URL: <http://code.djangoproject.com/ticket/12166#comment:2>
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@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: [Django] #12166: Instance.delete() cascade deletes related objects with null=True

by noreply-71 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12166: Instance.delete() cascade deletes related objects with null=True
------------------------------------+---------------------------------------
          Reporter:  oremj          |         Owner:  nobody
            Status:  closed         |     Milestone:        
         Component:  Uncategorized  |       Version:  1.1  
        Resolution:  duplicate      |      Keywords:        
             Stage:  Unreviewed     |     Has_patch:  0    
        Needs_docs:  0              |   Needs_tests:  0    
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by kmtracey):

  * status:  new => closed
  * resolution:  => duplicate

Comment:

 More options for delete behavior is the subject of #7539. Right now Django
 just does CASCADE. If that isn't what you want there are ways to get
 around it, see for example: http://stackoverflow.com/questions/1006135
 /how-do-i-create-a-django-model-with-foreignkeys-which-does-not-cascade-
 deletes-to

--
Ticket URL: <http://code.djangoproject.com/ticket/12166#comment:3>
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@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---