Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10399 -- Tested that o2o field updates are not constrained by …

…an inner query.
  • Loading branch information...
commit fb3d85bd14f1f7a8969ef8c54f2f0603e161f428 1 parent 952ba52
Simon Charette authored March 01, 2013

Showing 1 changed file with 25 additions and 1 deletion. Show diff stats Hide diff stats

  1. 26  tests/model_inheritance/tests.py
26  tests/model_inheritance/tests.py
... ...
@@ -1,9 +1,11 @@
1  
-from __future__ import absolute_import
  1
+from __future__ import absolute_import, unicode_literals
2 2
 
3 3
 from operator import attrgetter
4 4
 
5 5
 from django.core.exceptions import FieldError
  6
+from django.db import connection
6 7
 from django.test import TestCase
  8
+from django.test.testcases import CaptureQueriesContext
7 9
 from django.utils import six
8 10
 
9 11
 from .models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place,
@@ -294,3 +296,25 @@ def test_update_query_counts(self):
294 296
         )
295 297
         with self.assertNumQueries(6):
296 298
             ir.save()
  299
+
  300
+    def test_update_parent_filtering(self):
  301
+        """
  302
+        Test that updating a field of a model subclass doesn't issue an UPDATE
  303
+        query constrained by an inner query.
  304
+        Refs #10399
  305
+        """
  306
+        supplier = Supplier.objects.create(
  307
+            name='Central market',
  308
+            address='610 some street'
  309
+        )
  310
+        # Capture the expected query in a database agnostic way
  311
+        with CaptureQueriesContext(connection) as captured_queries:
  312
+            Place.objects.filter(pk=supplier.pk).update(name=supplier.name)
  313
+        expected_sql = captured_queries[0]['sql']
  314
+        # Capture the queries executed when a subclassed model instance is saved.
  315
+        with CaptureQueriesContext(connection) as captured_queries:
  316
+            supplier.save(update_fields=('name',))
  317
+        for query in captured_queries:
  318
+            sql = query['sql']
  319
+            if 'UPDATE' in sql:
  320
+                self.assertEqual(expected_sql, sql)

0 notes on commit fb3d85b

Please sign in to comment.
Something went wrong with that request. Please try again.