Fixed #28210 -- Fixed Model._state.adding on MTI parent model after saving child model.

Regression in 38575b007a.
This commit is contained in:
Tim Graham 2017-05-19 12:47:10 -04:00
parent 99df304c85
commit 59ab1b2683
3 changed files with 7 additions and 1 deletions

View File

@ -272,6 +272,7 @@ class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor):
if not any(field in fields for field in deferred):
kwargs = {field: getattr(instance, field) for field in fields}
obj = rel_model(**kwargs)
obj._state.adding = instance._state.adding
obj._state.db = instance._state.db
return obj
return super().get_object(instance)

View File

@ -25,3 +25,7 @@ Bugfixes
backends don't accept a positional ``request`` argument (:ticket:`28207`).
* Fixed introspection of index field ordering on PostgreSQL (:ticket:`28197`).
* Fixed a regression where ``Model._state.adding`` wasn't set correctly on
multi-table inheritance parent models after saving a child model
(:ticket:`28210`).

View File

@ -478,8 +478,9 @@ class ModelInheritanceTest(TestCase):
# The mismatch between Restaurant and Place is intentional (#28175).
self.assertSequenceEqual(Supplier.objects.filter(restaurant__in=Place.objects.all()), [s])
def test_ptr_accessor_assigns_db(self):
def test_ptr_accessor_assigns_state(self):
r = Restaurant.objects.create()
self.assertIs(r.place_ptr._state.adding, False)
self.assertEqual(r.place_ptr._state.db, 'default')
def test_related_filtering_query_efficiency_ticket_15844(self):