#28147: Saving parent object after setting on child leads to unexpected data 
loss
-------------------------------------+-------------------------------------
     Reporter:  Erwin Junge          |                    Owner:  robinh00d
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne):

 * cc: jon.dufresne@… (added)


Comment:

 This change caused a regression for a project I work on. When assigning a
 FK ID field to `None`, the FK is now restored on save. Here is a test to
 demonstrate that could be added to `many_to_one` tests.

 {{{
     def test_assign_fk_id_none(self):
         parent = Parent.objects.create(name='jeff')
         child = Child.objects.create(name='frank', parent=parent)
         parent.bestchild = child
         parent.save()
         parent.bestchild_id = None
         parent.save()
         self.assertIsNone(parent.bestchild_id)
         self.assertIsNone(parent.bestchild)
 }}}

 {{{
 ======================================================================
 FAIL: test_assign_fk_id_none (many_to_one.test_regression.MyTestCase)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File ".../django/tests/many_to_one/test_regression.py", line 14, in
 test_assign_fk_id_none
     self.assertIsNone(parent.bestchild_id)
 AssertionError: 1 is not None
 }}}

 Bisected to 519016e5f25d7c0a040015724f9920581551cab0.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28147#comment:15>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.cf0c12e62000ca86cfb2f1c07b09c03f%40djangoproject.com.

Reply via email to