Ticket #12328: t12328.diff
File t12328.diff, 5.0 KB (added by , 15 years ago) |
---|
-
django/db/models/query.py
diff -r 55950a87e230 django/db/models/query.py
a b 3 3 """ 4 4 5 5 from copy import deepcopy 6 from itertools import izip 6 7 7 8 from django.db import connections, router, transaction, IntegrityError 8 9 from django.db.models.aggregates import Aggregate … … 429 430 # becoming too long. 430 431 seen_objs = None 431 432 while 1: 432 # Collect a ll the objects to be deleted in this chunk, andall the433 # Collect a chunk of objects to be deleted, and then all the 433 434 # objects that are related to the objects that are to be deleted. 435 # The chunking *isn't* done by slicing the del_query because we 436 # need to maintain the query cache on del_query (see #12328) 434 437 seen_objs = CollectedObjects(seen_objs) 435 for object in del_query[:CHUNK_SIZE]:436 obj ect._collect_sub_objects(seen_objs)438 for i,obj in izip(range(CHUNK_SIZE), del_query): 439 obj._collect_sub_objects(seen_objs) 437 440 438 441 if not seen_objs: 439 442 break -
django/db/models/sql/compiler.py
diff -r 55950a87e230 django/db/models/sql/compiler.py
a b 120 120 """ 121 121 Perform the same functionality as the as_sql() method, returning an 122 122 SQL string and parameters. However, the alias prefixes are bumped 123 beforehand (in a copy -- the current query isn't changed) and any124 ordering is removed .123 beforehand (in a copy -- the current query isn't changed), and any 124 ordering is removed if the query is unsliced. 125 125 126 126 Used when nesting this query inside another. 127 127 """ 128 128 obj = self.query.clone() 129 obj.clear_ordering(True) 129 if obj.low_mark == 0 and obj.high_mark is None: 130 # If there is no slicing in use, then we can safely drop all ordering 131 obj.clear_ordering(True) 130 132 obj.bump_prefix() 131 133 return obj.get_compiler(connection=self.connection).as_sql() 132 134 -
tests/regressiontests/queries/models.py
diff -r 55950a87e230 tests/regressiontests/queries/models.py
a b 19 19 from django.utils.itercompat import sorted 20 20 21 21 class DumbCategory(models.Model): 22 pass 22 def __unicode__(self): 23 return unicode(self.id) 23 24 24 25 class NamedCategory(DumbCategory): 25 26 name = models.CharField(max_length=10) -
tests/regressiontests/queries/tests.py
diff -r 55950a87e230 tests/regressiontests/queries/tests.py
a b 1 1 import unittest 2 from models import Tag, Annotation 2 3 3 from django.db.models import Count 4 from django.test import TestCase 5 6 from models import Tag, Annotation, DumbCategory 4 7 5 8 class QuerysetOrderedTests(unittest.TestCase): 6 9 """ 7 10 Tests for the Queryset.ordered attribute. 8 11 """ 9 12 10 13 def test_no_default_or_explicit_ordering(self): 11 14 self.assertEqual(Annotation.objects.all().ordered, False) 12 15 13 16 def test_cleared_default_ordering(self): 14 17 self.assertEqual(Tag.objects.all().ordered, True) 15 18 self.assertEqual(Tag.objects.all().order_by().ordered, False) 16 19 17 20 def test_explicit_ordering(self): 18 21 self.assertEqual(Annotation.objects.all().order_by('id').ordered, True) 19 22 20 23 def test_order_by_extra(self): 21 24 self.assertEqual(Annotation.objects.all().extra(order_by=['id']).ordered, True) 22 25 23 26 def test_annotated_ordering(self): 24 27 qs = Annotation.objects.annotate(num_notes=Count('notes')) 25 28 self.assertEqual(qs.ordered, False) 26 29 self.assertEqual(qs.order_by('num_notes').ordered, True) 27 28 No newline at end of file 30 31 32 class SubqueryTests(TestCase): 33 def setUp(self): 34 DumbCategory.objects.create(id=1) 35 DumbCategory.objects.create(id=2) 36 DumbCategory.objects.create(id=3) 37 38 def test_ordered_subselect(self): 39 "Subselects can't have a manually specified ordering" 40 query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:2]).order_by('id') 41 self.assertEquals(repr(query), "[<DumbCategory: 2>, <DumbCategory: 3>]") 42 43 query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[:2]).order_by('id') 44 self.assertEquals(repr(query), "[<DumbCategory: 2>, <DumbCategory: 3>]") 45 46 query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[2:]).order_by('id') 47 self.assertEquals(repr(query), "[<DumbCategory: 1>]") 48 49 def test_sliced_delete(self): 50 DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:1]).delete() 51 self.assertEquals(repr(DumbCategory.objects.order_by('id')), "[<DumbCategory: 1>, <DumbCategory: 2>]")