Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19720 -- Oracle ordering related delete regression

When a query had a complex where condition (a condition targeting more
than the base table) a subquery was used for deletion. However, the
query had default ordering from the model's meta and Oracle doesn't
work with ordered subqueries.

The regression was caused by fast-path deletion code introduced in
1cd6e04 for fixing #18676.

Thanks to Dylan Klomparens for the report.
  • Loading branch information...
commit 8ef3235034a1a7616714a5d61486dc68536f74ee 1 parent 0478780
Anssi Kääriäinen authored February 10, 2013
2  django/db/models/query.py
@@ -539,7 +539,7 @@ def delete(self):
539 539
         # Disable non-supported fields.
540 540
         del_query.query.select_for_update = False
541 541
         del_query.query.select_related = False
542  
-        del_query.query.clear_ordering()
  542
+        del_query.query.clear_ordering(force_empty=True)
543 543
 
544 544
         collector = Collector(using=del_query.db)
545 545
         collector.collect(del_query)
10  tests/regressiontests/delete_regress/models.py
@@ -99,3 +99,13 @@ class OrgUnit(models.Model):
99 99
 class Login(models.Model):
100 100
     description = models.CharField(max_length=32)
101 101
     orgunit = models.ForeignKey(OrgUnit)
  102
+
  103
+class House(models.Model):
  104
+    address = models.CharField(max_length=32)
  105
+
  106
+class OrderedPerson(models.Model):
  107
+    name = models.CharField(max_length=32)
  108
+    lives_in = models.ForeignKey(House)
  109
+
  110
+    class Meta:
  111
+        ordering = ['name']
13  tests/regressiontests/delete_regress/tests.py
@@ -10,7 +10,7 @@
10 10
 from .models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith,
11 11
     PlayedWithNote, Email, Researcher, Food, Eaten, Policy, Version, Location,
12 12
     Item, Image, File, Photo, FooFile, FooImage, FooPhoto, FooFileProxy, Login,
13  
-    OrgUnit)
  13
+    OrgUnit, OrderedPerson, House)
14 14
 
15 15
 
16 16
 # Can't run this test under SQLite, because you can't
@@ -347,3 +347,14 @@ def test_ticket_19102_defer(self):
347 347
         self.assertFalse(Login.objects.filter(pk=self.l1.pk).exists())
348 348
         self.assertTrue(Login.objects.filter(pk=self.l2.pk).exists())
349 349
 
  350
+
  351
+class OrderedDeleteTests(TestCase):
  352
+    def test_meta_ordered_delete(self):
  353
+        # When a subquery is performed by deletion code, the subquery must be
  354
+        # cleared of all ordering. There was a but that caused _meta ordering
  355
+        # to be used. Refs #19720.
  356
+        h = House.objects.create(address='Foo')
  357
+        OrderedPerson.objects.create(name='Jack', lives_in=h)
  358
+        OrderedPerson.objects.create(name='Bob', lives_in=h)
  359
+        OrderedPerson.objects.filter(lives_in__address='Foo').delete()
  360
+        self.assertEqual(OrderedPerson.objects.count(), 0)

0 notes on commit 8ef3235

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