#29085: Possible data loss on .save() with unsaved related model
-------------------------------------+-------------------------------------
               Reporter:  Jonas      |          Owner:  nobody
  Haag                               |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 - Create unsaved model C
 - Assign unsaved related model P
 - Save related model P and C
 - Relationship is lost

 This is similar to #25160 I guess?

 I reproduced this with all versions of Django 1.6 up to master.

 {{{
 from django.db import models


 class Parent(models.Model):
     pass


 class Child(models.Model):
     parent = models.ForeignKey(Parent, null=True, blank=True,
 on_delete=models.CASCADE)
 }}}

 {{{
 from .models import Parent, Child
 from django.test import TestCase

 class MyTest(TestCase):
     def test_save(self):
         child = Child()
         child.parent = Parent()
         child.parent.save()
         # This makes the problem go away:
         # child.parent = child.parent
         child.save()
         child.refresh_from_db()
         self.assertIsNotNone(child.parent)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29085>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.1e0d4a0bdb18d7d1ecd640852a26fef8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to