#33322: bulk_update not working with foreign key when referenced model was saved
after the assignment.
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
GwynBleidD |
Type: Bug | Status: new
Component: Database | Version: 3.2
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 |
-------------------------------------+-------------------------------------
Consider following example:
{{{
class Child(models.Model):
pass
class Parent(models.Model):
child = models.ForeignKey(Child, on_delete=models.CASCADE, null=True)
}}}
{{{
parent = Parent.objects.create(child=None)
parent.child = Child()
parent.child.save()
Parent.objects.bulk_update([parent], fields=["child"])
}}}
Expected behavior:
parent model instance was updated with the ID to the child in the
database.
Actual behavior:
Parent model is still referencing Null.
There should probably be some check for ForeignKeys in the bulk_update
logic, and if one is updated, the ID of the child model should be re-
copied to the child_id field that is actually being written to the
database.
--
Ticket URL: <https://code.djangoproject.com/ticket/33322>
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/049.289b09b7ffb0dd947f18700321a7d97f%40djangoproject.com.