Author: russellm Date: 2010-04-03 06:47:46 -0500 (Sat, 03 Apr 2010) New Revision: 12911
Added: django/branches/releases/1.1.X/tests/modeltests/update/tests.py Modified: django/branches/releases/1.1.X/django/db/models/sql/subqueries.py django/branches/releases/1.1.X/tests/modeltests/update/models.py Log: [1.1.X] Fixed #12247 -- Corrected the way update queries are processed when the update only refers to attributes on a base class. Thanks to jsmullyan for the report, and matiasb for the fix. Backport of r12910 from trunk. Modified: django/branches/releases/1.1.X/django/db/models/sql/subqueries.py =================================================================== --- django/branches/releases/1.1.X/django/db/models/sql/subqueries.py 2010-04-03 11:45:31 UTC (rev 12910) +++ django/branches/releases/1.1.X/django/db/models/sql/subqueries.py 2010-04-03 11:47:46 UTC (rev 12911) @@ -284,7 +284,7 @@ for model, values in self.related_updates.iteritems(): query = UpdateQuery(model, self.connection) query.values = values - if self.related_ids: + if self.related_ids is not None: query.add_filter(('pk__in', self.related_ids)) result.append(query) return result Modified: django/branches/releases/1.1.X/tests/modeltests/update/models.py =================================================================== --- django/branches/releases/1.1.X/tests/modeltests/update/models.py 2010-04-03 11:45:31 UTC (rev 12910) +++ django/branches/releases/1.1.X/tests/modeltests/update/models.py 2010-04-03 11:47:46 UTC (rev 12911) @@ -21,6 +21,19 @@ return unicode(self.name) +class A(models.Model): + x = models.IntegerField(default=10) + +class B(models.Model): + a = models.ForeignKey(A) + y = models.IntegerField(default=10) + +class C(models.Model): + y = models.IntegerField(default=10) + +class D(C): + a = models.ForeignKey(A) + __test__ = {'API_TESTS': """ >>> DataPoint(name="d0", value="apple").save() >>> DataPoint(name="d2", value="banana").save() Added: django/branches/releases/1.1.X/tests/modeltests/update/tests.py =================================================================== --- django/branches/releases/1.1.X/tests/modeltests/update/tests.py (rev 0) +++ django/branches/releases/1.1.X/tests/modeltests/update/tests.py 2010-04-03 11:47:46 UTC (rev 12911) @@ -0,0 +1,49 @@ +from django.test import TestCase + +from models import A, B, D + +class SimpleTest(TestCase): + def setUp(self): + self.a1 = A.objects.create() + self.a2 = A.objects.create() + for x in range(20): + B.objects.create(a=self.a1) + D.objects.create(a=self.a1) + + def test_nonempty_update(self): + """ + Test that update changes the right number of rows for a nonempty queryset + """ + num_updated = self.a1.b_set.update(y=100) + self.failUnlessEqual(num_updated, 20) + cnt = B.objects.filter(y=100).count() + self.failUnlessEqual(cnt, 20) + + def test_empty_update(self): + """ + Test that update changes the right number of rows for an empty queryset + """ + num_updated = self.a2.b_set.update(y=100) + self.failUnlessEqual(num_updated, 0) + cnt = B.objects.filter(y=100).count() + self.failUnlessEqual(cnt, 0) + + def test_nonempty_update_with_inheritance(self): + """ + Test that update changes the right number of rows for an empty queryset + when the update affects only a base table + """ + num_updated = self.a1.d_set.update(y=100) + self.failUnlessEqual(num_updated, 20) + cnt = D.objects.filter(y=100).count() + self.failUnlessEqual(cnt, 20) + + def test_empty_update_with_inheritance(self): + """ + Test that update changes the right number of rows for an empty queryset + when the update affects only a base table + """ + num_updated = self.a2.d_set.update(y=100) + self.failUnlessEqual(num_updated, 0) + cnt = D.objects.filter(y=100).count() + self.failUnlessEqual(cnt, 0) -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.