From d065c92678f5d11a70b88e195c6357576eb3a2ef Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 30 Dec 2017 18:00:36 -0500 Subject: [PATCH] Fixed #28918 -- Fixed Model.refresh_from_db() for instances hidden by the default manager. --- django/db/models/base.py | 2 +- tests/custom_managers/tests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 2588ee3ff6..5633fff89a 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -591,7 +591,7 @@ class Model(metaclass=ModelBase): 'are not allowed in fields.' % LOOKUP_SEP) 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. deferred_fields = self.get_deferred_fields() diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index ee2ac1d552..a545382d8f 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -607,6 +607,16 @@ class CustomManagersRegressTestCase(TestCase): # there would now be two objects in the database. 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): """Deleting related objects should also not be distracted by a restricted manager on the related object. This is a regression