Opened 8 years ago
Last modified 5 years ago
#28147 closed Bug
Saving parent object after setting on child leads to unexpected data loss — at Version 1
Reported by: | Erwin Junge | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Tim Martin, jon.dufresne@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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
Note:
See TracTickets
for help on using tickets.