Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2013-08-23 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
-+-
 Reporter:  theevilgeek  |Owner:  Anssi
 Type:  Bug  |  Kääriäinen 
Component:  Database layer   |   Status:  closed
  (models, ORM)  |  Version:  master
 Severity:  Normal   |   Resolution:  fixed
 Keywords:  OneToOneField,   | Triage Stage:  Accepted
  cascading delete, nullable |  Needs documentation:  0
Has patch:  1|  Patch needs improvement:  1
  Needs tests:  1|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by Andrew Godwin ):

 In [changeset:"b773ef8fa0ef09641abf376ca8d4083d8966ec52"]:
 {{{
 #!CommitTicketReference repository=""
 revision="b773ef8fa0ef09641abf376ca8d4083d8966ec52"
 Fixed #14043 -- Made sure nullable o2o delete works as expected

 There was an old complaint about nullable one-to-one field cascading
 even when the o2o field was saved to None value before the deletion.
 Added an test to verify this doesn't happen.

 Also some PEP 8 cleanup.
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.4c0de3e88d8bf1782ca9938f4e453988%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2013-08-19 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
-+-
 Reporter:  theevilgeek  |Owner:  Anssi
 Type:  Bug  |  Kääriäinen 
Component:  Database layer   |   Status:  closed
  (models, ORM)  |  Version:  master
 Severity:  Normal   |   Resolution:  fixed
 Keywords:  OneToOneField,   | Triage Stage:  Accepted
  cascading delete, nullable |  Needs documentation:  0
Has patch:  1|  Patch needs improvement:  1
  Needs tests:  1|UI/UX:  0
Easy pickings:  0|
-+-
Changes (by Anssi Kääriäinen ):

 * status:  new => closed
 * owner:   => Anssi Kääriäinen 
 * resolution:   => fixed


Comment:

 In [changeset:"b53ed351b34918e337cbf26773998dafc6f82f4d"]:
 {{{
 #!CommitTicketReference repository=""
 revision="b53ed351b34918e337cbf26773998dafc6f82f4d"
 Fixed #14043 -- Made sure nullable o2o delete works as expected

 There was an old complaint about nullable one-to-one field cascading
 even when the o2o field was saved to None value before the deletion.
 Added an test to verify this doesn't happen.

 Also some PEP 8 cleanup.
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.c5a1f32df1851cdda2c951b1a8faaeec%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2013-08-19 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
-+-
 Reporter:  theevilgeek  |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:  OneToOneField,   |  Needs documentation:  0
  cascading delete, nullable |  Patch needs improvement:  1
Has patch:  1|UI/UX:  0
  Needs tests:  1|
Easy pickings:  0|
-+-

Comment (by akaariai):

 I can confirm that this does still happen in master. I tested with this in
 one_to_one_regress:
 {{{

 def test_nullable_o2o_delete(self):
 u = UndergroundBar.objects.create(place=self.p1)
 self.p1.delete()
 self.assertTrue(UndergroundBar.objects.filter(pk=u.pk).exists())
 self.assertIsNone(UndergroundBar.objects.get(pk=u.pk).place)
 }}}

 The attached patch isn't correct at all, it is explicitly breaking the
 link before delete and then confirming that delete doesn't cascade after
 that. That isn't the problem, the problem is that OneToOneField that is
 nullable should be set to None on delete, not cascaded.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.1ab8b8b0f0a0afe720b3b8115cf1fcec%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2011-02-23 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
+---
   Reporter:  theevilgeek   | Owner:
   
 Status:  new   | Milestone:  1.3   
   
  Component:  Database layer (models, ORM)  |   Version:  SVN   
   
 Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
   Triage Stage:  Accepted  | Has patch:  1 
   
Needs documentation:  0 |   Needs tests:  1 
   
Patch needs improvement:  1 |  
+---
Changes (by russellm):

  * needs_better_patch:  0 => 1
  * needs_tests:  0 => 1
  * stage:  Ready for checkin => Accepted


Comment:

 The provided test case doesn't validate the problem described. If you
 revert the change to related.py, the test case doesn't fail.

-- 
Ticket URL: 
Django 
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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-11-22 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone:  1.3
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Ready for checkin | Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Comment (by ahebert):

 Looks like this is solved here. I'm adding a little more information for
 anyone who is trying to work around this in a pre-1.3 version of Django.
 The following modification fixed a similar problem on my model.


 {{{
 class Person(models.Model):
   age = models.PositiveIntegerField()

   def die(self):
 self.soul.become_ghost()
 # Update self here, so that self.soul is unavailalbe in the object
 passed to delete()
 # If self is left alone, then self.soul points to a python object
 representing a relationship
 # that was deleted from the database in the call to become_ghost().
 self = Person.objects.get(pk=self.pk)
 # OR, the following to work more generally:
 # self = self.__class__.objects.get(pk=self.pk)
 self.delete()


 class Soul(models.Model):
   person = models.OneToOneField(Person, null=True)
   is_alive = models.BooleanField(default=True)

   def become_ghost(self):
 self.person = None
 self.is_alive = False
 self.save()

 }}}

 I'd suggest it as a documentation change for earlier versions, but it's so
 hack-y.

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-10-23 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone:  1.3
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Ready for checkin | Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by anonymous):

  * milestone:  => 1.3

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-10-09 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Ready for checkin | Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by gsakkis):

  * has_patch:  0 => 1
  * stage:  Design decision needed => Ready for checkin

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-09-30 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Design decision needed| Has_patch:  0  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by gsakkis):

  * stage:  Accepted => Design decision needed

Comment:

 Replying to [comment:1 gsakkis]:
 >
 > Why do an update if it is going to be deleted right after ?

 Ugh, scratch that, I missed the `self.save()` in `become_ghost()`, that's
 where the UPDATE comes from; nothing to do with `self.delete()`.

 Back to the topic, it comes down to Django's indiscriminate ON DELETE
 CASCADE behavior, regardless of whether the ForeignKey/OneToOneField is
 nullable. IMO it would make more sense to treat nullable keys as ON DELETE
 SET NULL but that would most likely be backwards incompatible at this
 point. Changing to design decision needed, just in case.

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-09-28 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Accepted  | Has_patch:  0  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by russellm):

  * stage:  Unreviewed => Accepted

Comment:

 @gsakkis - You use the triage stage, not the action. Confusing, I know...
 :-)

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-09-28 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Unreviewed| Has_patch:  0  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Comment (by gsakkis):

 Ugh, selecting "accept ticket" makes me the ticket owner. What's the way
 to say "I confirm the ticket is legit" without marking me as responsible
 for it ?

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-09-28 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner: 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Unreviewed| Has_patch:  0  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by gsakkis):

  * owner:  gsakkis =>
  * status:  assigned => new

-- 
Ticket URL: 
Django 
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-upda...@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.



Re: [Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-09-28 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
  Reporter:  theevilgeek   | Owner:  gsakkis
  
Status:  assigned  | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
OneToOneField, cascading delete, nullable
 Stage:  Unreviewed| Has_patch:  0  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by gsakkis):

  * status:  new => assigned
 * cc: gsakkis (added)
  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * owner:  nobody => gsakkis
  * needs_docs:  => 0

Comment:

 Confirmed here too, it's definitely non obvious, if not outright a bug.
 Also the SQL being issued on `bob.delete()` hints that something is fishy:
 {{{
 In [11]: bob.delete()
 UPDATE `lib_soul`
 SET `person_id` = NULL
 WHERE `id` IN (4)

 DELETE
 FROM `lib_soul`
 WHERE `id` IN (4)

 DELETE
 FROM `lib_person`
 WHERE `id` IN (2)
 }}}

 Why do an update if it is going to be deleted right after ?

-- 
Ticket URL: 
Django 
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-upda...@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.



[Django] #14043: Incorrect and/or confusing behaviour with nullable OneToOneField

2010-08-01 Thread Django
#14043: Incorrect and/or confusing behaviour with nullable OneToOneField
---+
 Reporter:  theevilgeek|   Owner:  nobody   
 
   Status:  new|   Milestone:   
 
Component:  Database layer (models, ORM)   | Version:  SVN  
 
 Keywords:  OneToOneField, cascading delete, nullable  |   Stage:  
Unreviewed
Has_patch:  0  |  
---+
 Attempting to "null" out a nullable OneToOneField before deleting the
 related object fails to prevent a cascading delete (i.e., both objects are
 still deleted whereas it seems only the related object ought to be
 deleted).

 Example code:

 {{{

 # Note: using Django trunk

 ## MODELS ##

 class Person(models.Model):
   age = models.PositiveIntegerField()

   def die(self):
 self.soul.become_ghost()
 self.delete()


 class Soul(models.Model):
   person = models.OneToOneField(Person, null=True)
   is_alive = models.BooleanField(default=True)

   def become_ghost(self):
 self.person = None
 self.is_alive = False
 self.save()


 ## TESTCASE (INTERACTIVE) ##

 # Type a few commands in "python manage.py shell"

 >>> from app.models import Person, Soul
 >>>
 >>> bob = Person.objects.create(age=34)
 >>> bobs_soul = Soul.objects.create(person=bob)

 # Let's see what's happening in MySQL (switching programs...)

 mysql> select * from app_person;
 ++-+
 | id | age |
 ++-+
 |  2 |  34 |
 ++-+
 1 row in set (0.00 sec)

 mysql> select * from app_soul;
 ++---+--+
 | id | person_id | is_alive |
 ++---+--+
 |  2 | 2 |1 |
 ++---+--+
 1 row in set (0.00 sec)

 # Okay, that looks good; let's kill him (switching programs again...)

 >>> bob.die()

 # Back to MySQL

 mysql> select * from app_person;
 Empty set (0.00 sec)

 mysql> select * from app_soul;
 Empty set (0.00 sec)

 ### Huh!??! Why is app_soul being deleted?

 }}}

-- 
Ticket URL: 
Django 
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-upda...@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.