mirror of https://github.com/django/django.git
Fixed #28918 -- Fixed Model.refresh_from_db() for instances hidden by the default manager.
This commit is contained in:
parent
dcdd219ee1
commit
d065c92678
|
@ -591,7 +591,7 @@ class Model(metaclass=ModelBase):
|
||||||
'are not allowed in fields.' % LOOKUP_SEP)
|
'are not allowed in fields.' % LOOKUP_SEP)
|
||||||
|
|
||||||
db = using if using is not None else self._state.db
|
db = using if using is not None else self._state.db
|
||||||
db_instance_qs = self.__class__._default_manager.using(db).filter(pk=self.pk)
|
db_instance_qs = self.__class__._base_manager.using(db).filter(pk=self.pk)
|
||||||
|
|
||||||
# Use provided fields, if not set then reload all non-deferred fields.
|
# Use provided fields, if not set then reload all non-deferred fields.
|
||||||
deferred_fields = self.get_deferred_fields()
|
deferred_fields = self.get_deferred_fields()
|
||||||
|
|
|
@ -607,6 +607,16 @@ class CustomManagersRegressTestCase(TestCase):
|
||||||
# there would now be two objects in the database.
|
# there would now be two objects in the database.
|
||||||
self.assertEqual(RestrictedModel.plain_manager.count(), 1)
|
self.assertEqual(RestrictedModel.plain_manager.count(), 1)
|
||||||
|
|
||||||
|
def test_refresh_from_db_when_default_manager_filters(self):
|
||||||
|
"""
|
||||||
|
Model.refresh_from_db() works for instances hidden by the default
|
||||||
|
manager.
|
||||||
|
"""
|
||||||
|
book = Book._base_manager.create(is_published=False)
|
||||||
|
Book._base_manager.filter(pk=book.pk).update(title='Hi')
|
||||||
|
book.refresh_from_db()
|
||||||
|
self.assertEqual(book.title, 'Hi')
|
||||||
|
|
||||||
def test_delete_related_on_filtered_manager(self):
|
def test_delete_related_on_filtered_manager(self):
|
||||||
"""Deleting related objects should also not be distracted by a
|
"""Deleting related objects should also not be distracted by a
|
||||||
restricted manager on the related object. This is a regression
|
restricted manager on the related object. This is a regression
|
||||||
|
|
Loading…
Reference in New Issue