#32133: bulk_create of parent after setting on child leads to unexpected data 
loss
-------------------------------------+-------------------------------------
               Reporter:  Hannes     |          Owner:  Hannes Ljungberg
  Ljungberg                          |
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  3.1
  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          |
-------------------------------------+-------------------------------------
 I think this is a missed case of
 https://code.djangoproject.com/ticket/28147. The behaviour is exactly the
 same but affects `bulk_update`.

 Failing testcase:
 {{{
 parent = NoFields()
 child = NullableFields(auto_field=parent)
 NoFields.objects.bulk_create([parent])
 NullableFields.objects.bulk_create([child])
 child.refresh_from_db()
 self.assertEqual(child.auto_field, parent)
 }}}

 This behaviour was also described in
 https://code.djangoproject.com/ticket/29497 but might’ve been missed when
 closed as a duplicate.

 My proposal is to extract the code in `Model.save()` which ensures that
 all fields are in sync before save to it’s own method which can then be
 used by `bulk_update`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32133>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.b26786247f0173db2fdd7355d531e3f8%40djangoproject.com.

Reply via email to