[1.11.x] Fixed #28166 -- Fixed Model._state.db on MTI parent model after saving child model.
Regression in38575b007a
. Backport of584e10c76e
from master
This commit is contained in:
parent
008ba77dfd
commit
f3217ab596
|
@ -288,7 +288,9 @@ class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor):
|
||||||
# on the related model for every deferred field.
|
# on the related model for every deferred field.
|
||||||
if not any(field in fields for field in deferred):
|
if not any(field in fields for field in deferred):
|
||||||
kwargs = {field: getattr(instance, field) for field in fields}
|
kwargs = {field: getattr(instance, field) for field in fields}
|
||||||
return rel_model(**kwargs)
|
obj = rel_model(**kwargs)
|
||||||
|
obj._state.db = instance._state.db
|
||||||
|
return obj
|
||||||
return super(ForwardOneToOneDescriptor, self).get_object(instance)
|
return super(ForwardOneToOneDescriptor, self).get_object(instance)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,3 +84,7 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed crash in ``BaseInlineFormSet._construct_form()`` when using
|
* Fixed crash in ``BaseInlineFormSet._construct_form()`` when using
|
||||||
``save_as_new`` (:ticket:`28159`).
|
``save_as_new`` (:ticket:`28159`).
|
||||||
|
|
||||||
|
* Fixed a regression where ``Model._state.db`` wasn't set correctly on
|
||||||
|
multi-table inheritance parent models after saving a child model
|
||||||
|
(:ticket:`28166`).
|
||||||
|
|
|
@ -474,6 +474,10 @@ class ModelInheritanceTest(TestCase):
|
||||||
jane = Supplier.objects.order_by("name").select_related("restaurant")[0]
|
jane = Supplier.objects.order_by("name").select_related("restaurant")[0]
|
||||||
self.assertEqual(jane.restaurant.name, "Craft")
|
self.assertEqual(jane.restaurant.name, "Craft")
|
||||||
|
|
||||||
|
def test_ptr_accessor_assigns_db(self):
|
||||||
|
r = Restaurant.objects.create()
|
||||||
|
self.assertEqual(r.place_ptr._state.db, 'default')
|
||||||
|
|
||||||
def test_related_filtering_query_efficiency_ticket_15844(self):
|
def test_related_filtering_query_efficiency_ticket_15844(self):
|
||||||
r = Restaurant.objects.create(
|
r = Restaurant.objects.create(
|
||||||
name="Guido's House of Pasta",
|
name="Guido's House of Pasta",
|
||||||
|
|
Loading…
Reference in New Issue