[Django] #32133: bulk_create of parent after setting on child leads to unexpected data loss

9 views
Skip to first unread message

Django

unread,
Oct 22, 2020, 3:03:52 PM10/22/20
to django-...@googlegroups.com
#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.

Django

unread,
Oct 22, 2020, 3:06:12 PM10/22/20
to django-...@googlegroups.com
#32133: bulk_create of parent after setting on child leads to unexpected data loss
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes

| Ljungberg
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/13589

--
Ticket URL: <https://code.djangoproject.com/ticket/32133#comment:1>

Reply all
Reply to author
Forward
0 new messages