#28147: Saving parent object after setting on child leads to unexpected data
loss
-------------------------------------+-------------------------------------
Reporter: Erwin Junge | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(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
-------------------------------------+-------------------------------------
Description changed by Erwin Junge:
Old description:
> When saving a parent object after setting it on a child object and then
> saving the child object, no error is thrown but the FK relation is saved
> with a NULL value.
>
> Failing testcase:
> {{{
> # Create parent and child, save parent, save child, parent_id
> should be set
> p = Parent()
> c = Child(parent=p)
> p.save()
> c.save()
> c.refresh_from_db()
> self.assertIs(c.parent, p)
> }}}
New description:
When saving a parent object after setting it on a child object and then
saving the child object, no error is thrown but the FK relation is saved
with a NULL value.
Failing testcase:
{{{
# Create parent and child, save parent, save child, parent_id
should be set
p = Parent()
c = Child(parent=p)
p.save()
c.save()
c.refresh_from_db()
self.assertIs(c.parent, p)
}}}
Patch available: https://github.com/django/django/pull/8434
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28147#comment:1>
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/068.2571f3636b63791f818f8209f4bd1b64%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.