From 54e5c4a00e116ff4be257accdc9aa9e068c7f4ee Mon Sep 17 00:00:00 2001 From: Yan Mitrofanov Date: Mon, 20 Nov 2017 18:25:01 +0300 Subject: [PATCH] Fixed #28820 -- Eliminated an extra query with QuerySet.update() on proxy models. --- django/db/models/sql/subqueries.py | 2 +- tests/proxy_models/tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index edff51a56a..e877daa4e6 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -122,7 +122,7 @@ class UpdateQuery(Query): 'Cannot update model field %r (only non-relations and ' 'foreign keys permitted).' % field ) - if model is not self.get_meta().model: + if model is not self.get_meta().concrete_model: self.add_related_update(model, field, val) continue values_seq.append((field, model, val)) diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py index 5fdfbfb6bf..50d2c57dd4 100644 --- a/tests/proxy_models/tests.py +++ b/tests/proxy_models/tests.py @@ -276,6 +276,13 @@ class ProxyModelTests(TestCase): resp = [u.name for u in UserProxy.objects.all()] self.assertEqual(resp, ['Bruce']) + def test_proxy_update(self): + user = User.objects.create(name='Bruce') + with self.assertNumQueries(1): + UserProxy.objects.filter(id=user.id).update(name='George') + user.refresh_from_db() + self.assertEqual(user.name, 'George') + def test_select_related(self): """ We can still use `select_related()` to include related models in our