Skip to content

Commit

Permalink
Fixed #28820 -- Eliminated an extra query with QuerySet.update() on p…
Browse files Browse the repository at this point in the history
…roxy models.
  • Loading branch information
Yan Mitrofanov authored and timgraham committed Nov 21, 2017
1 parent a5f1e58 commit 54e5c4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/models/sql/subqueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def add_update_values(self, values):
'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))
Expand Down
7 changes: 7 additions & 0 deletions tests/proxy_models/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def test_proxy_delete(self):
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
Expand Down

0 comments on commit 54e5c4a

Please sign in to comment.