﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29085	Possible data loss on .save() with unsaved related model.	Jonas Haag	nobody	"- Create unsaved model C
- Assign unsaved related model P
- Save related model P and C
- Relationship is lost

This is similar to #25160 I guess?

I reproduced this with all versions of Django 1.6 up to master.

{{{
from django.db import models


class Parent(models.Model):
    pass


class Child(models.Model):
    parent = models.ForeignKey(Parent, null=True, blank=True, on_delete=models.CASCADE)
}}}

{{{
from .models import Parent, Child
from django.test import TestCase

class MyTest(TestCase):
    def test_save(self):
        child = Child()
        child.parent = Parent()
        child.parent.save()
        # This makes the problem go away:
        # child.parent = child.parent
        child.save()
        child.refresh_from_db()
        self.assertIsNotNone(child.parent)
}}}"	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	duplicate			Accepted	0	0	0	0	0	0
