Fixed #10250 -- Added a regression test to ensure that GROUP BY statements are correctly quoted under MySQL. This appears to have been corrected inadvertently since the original report, but the extra regression test will make sure it stays that way.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10043 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5eccc59652
commit
6d17020c1a
|
@ -7,54 +7,44 @@ except NameError:
|
||||||
from django.utils.itercompat import sorted # For Python 2.3
|
from django.utils.itercompat import sorted # For Python 2.3
|
||||||
|
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
age = models.IntegerField()
|
age = models.IntegerField()
|
||||||
friends = models.ManyToManyField('self', blank=True)
|
friends = models.ManyToManyField('self', blank=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Publisher(models.Model):
|
class Publisher(models.Model):
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
num_awards = models.IntegerField()
|
num_awards = models.IntegerField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
isbn = models.CharField(max_length=9)
|
isbn = models.CharField(max_length=9)
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
pages = models.IntegerField()
|
pages = models.IntegerField()
|
||||||
rating = models.FloatField()
|
rating = models.FloatField()
|
||||||
price = models.DecimalField(decimal_places=2, max_digits=6)
|
price = models.DecimalField(decimal_places=2, max_digits=6)
|
||||||
authors = models.ManyToManyField(Author)
|
authors = models.ManyToManyField(Author)
|
||||||
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
||||||
publisher = models.ForeignKey(Publisher)
|
publisher = models.ForeignKey(Publisher)
|
||||||
pubdate = models.DateField()
|
pubdate = models.DateField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Store(models.Model):
|
class Store(models.Model):
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
books = models.ManyToManyField(Book)
|
books = models.ManyToManyField(Book)
|
||||||
original_opening = models.DateTimeField()
|
original_opening = models.DateTimeField()
|
||||||
friday_night_closing = models.TimeField()
|
friday_night_closing = models.TimeField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Entries(models.Model):
|
# Tests on 'aggregate'
|
||||||
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
|
|
||||||
Entry = models.CharField(unique=True, max_length=50)
|
|
||||||
Exclude = models.BooleanField()
|
|
||||||
|
|
||||||
class Clues(models.Model):
|
|
||||||
ID = models.AutoField(primary_key=True)
|
|
||||||
EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
|
|
||||||
Clue = models.CharField(max_length=150)
|
|
||||||
|
|
||||||
# Tests on 'aggergate'
|
|
||||||
# Different backends and numbers.
|
# Different backends and numbers.
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
>>> from django.core import management
|
>>> from django.core import management
|
||||||
|
@ -351,10 +341,6 @@ True
|
||||||
# Cheating: [a for a in Author.objects.all().annotate(num_coleagues=Count('book__authors__id'), num_books=Count('book__id', distinct=True)) if a.num_coleagues - a.num_books > 0]
|
# Cheating: [a for a in Author.objects.all().annotate(num_coleagues=Count('book__authors__id'), num_books=Count('book__id', distinct=True)) if a.num_coleagues - a.num_books > 0]
|
||||||
# F-Syntax is required. Will be fixed after F objects are available
|
# F-Syntax is required. Will be fixed after F objects are available
|
||||||
|
|
||||||
# Tests on fields with non-default table and column names.
|
|
||||||
>>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
|
|
||||||
[]
|
|
||||||
|
|
||||||
# Aggregates also work on dates, times and datetimes
|
# Aggregates also work on dates, times and datetimes
|
||||||
>>> Publisher.objects.annotate(earliest_book=Min('book__pubdate')).exclude(earliest_book=None).order_by('earliest_book').values()
|
>>> Publisher.objects.annotate(earliest_book=Min('book__pubdate')).exclude(earliest_book=None).order_by('earliest_book').values()
|
||||||
[{'earliest_book': datetime.date(1991, 10, 15), 'num_awards': 9, 'id': 4, 'name': u'Morgan Kaufmann'}, {'earliest_book': datetime.date(1995, 1, 15), 'num_awards': 7, 'id': 3, 'name': u'Prentice Hall'}, {'earliest_book': datetime.date(2007, 12, 6), 'num_awards': 3, 'id': 1, 'name': u'Apress'}, {'earliest_book': datetime.date(2008, 3, 3), 'num_awards': 1, 'id': 2, 'name': u'Sams'}]
|
[{'earliest_book': datetime.date(1991, 10, 15), 'num_awards': 9, 'id': 4, 'name': u'Morgan Kaufmann'}, {'earliest_book': datetime.date(1995, 1, 15), 'num_awards': 7, 'id': 3, 'name': u'Prentice Hall'}, {'earliest_book': datetime.date(2007, 12, 6), 'num_awards': 3, 'id': 1, 'name': u'Apress'}, {'earliest_book': datetime.date(2008, 3, 3), 'num_awards': 1, 'id': 2, 'name': u'Sams'}]
|
||||||
|
|
|
@ -8,47 +8,56 @@ except NameError:
|
||||||
from django.utils.itercompat import sorted # For Python 2.3
|
from django.utils.itercompat import sorted # For Python 2.3
|
||||||
|
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
age = models.IntegerField()
|
age = models.IntegerField()
|
||||||
friends = models.ManyToManyField('self', blank=True)
|
friends = models.ManyToManyField('self', blank=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Publisher(models.Model):
|
class Publisher(models.Model):
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
num_awards = models.IntegerField()
|
num_awards = models.IntegerField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
isbn = models.CharField(max_length=9)
|
isbn = models.CharField(max_length=9)
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
pages = models.IntegerField()
|
pages = models.IntegerField()
|
||||||
rating = models.FloatField()
|
rating = models.FloatField()
|
||||||
price = models.DecimalField(decimal_places=2, max_digits=6)
|
price = models.DecimalField(decimal_places=2, max_digits=6)
|
||||||
authors = models.ManyToManyField(Author)
|
authors = models.ManyToManyField(Author)
|
||||||
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
||||||
publisher = models.ForeignKey(Publisher)
|
publisher = models.ForeignKey(Publisher)
|
||||||
pubdate = models.DateField()
|
pubdate = models.DateField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Store(models.Model):
|
class Store(models.Model):
|
||||||
name = models.CharField(max_length=300)
|
name = models.CharField(max_length=300)
|
||||||
books = models.ManyToManyField(Book)
|
books = models.ManyToManyField(Book)
|
||||||
original_opening = models.DateTimeField()
|
original_opening = models.DateTimeField()
|
||||||
friday_night_closing = models.TimeField()
|
friday_night_closing = models.TimeField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class Entries(models.Model):
|
||||||
|
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
|
||||||
|
Entry = models.CharField(unique=True, max_length=50)
|
||||||
|
Exclude = models.BooleanField()
|
||||||
|
|
||||||
|
class Clues(models.Model):
|
||||||
|
ID = models.AutoField(primary_key=True)
|
||||||
|
EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
|
||||||
|
Clue = models.CharField(max_length=150)
|
||||||
|
|
||||||
#Extra does not play well with values. Modify the tests if/when this is fixed.
|
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
>>> from django.core import management
|
>>> from django.core import management
|
||||||
>>> from django.db.models import get_app, F
|
>>> from django.db.models import get_app, F
|
||||||
|
@ -188,6 +197,13 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta
|
||||||
>>> Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
|
>>> Publisher.objects.annotate(num_books=Count('book')).exclude(num_books__lt=F('num_awards')/2).order_by('name').values('name','num_books','num_awards')
|
||||||
[{'num_books': 2, 'name': u'Apress', 'num_awards': 3}, {'num_books': 0, 'name': u"Jonno's House of Books", 'num_awards': 0}, {'num_books': 1, 'name': u'Sams', 'num_awards': 1}]
|
[{'num_books': 2, 'name': u'Apress', 'num_awards': 3}, {'num_books': 0, 'name': u"Jonno's House of Books", 'num_awards': 0}, {'num_books': 1, 'name': u'Sams', 'num_awards': 1}]
|
||||||
|
|
||||||
|
# Tests on fields with non-default table and column names.
|
||||||
|
>>> Clues.objects.values('EntryID__Entry').annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
|
||||||
|
[]
|
||||||
|
|
||||||
|
>>> Entries.objects.annotate(clue_count=Count('clues__ID'))
|
||||||
|
[]
|
||||||
|
|
||||||
# Regression for #10089: Check handling of empty result sets with aggregates
|
# Regression for #10089: Check handling of empty result sets with aggregates
|
||||||
>>> Book.objects.filter(id__in=[]).count()
|
>>> Book.objects.filter(id__in=[]).count()
|
||||||
0
|
0
|
||||||
|
|
Loading…
Reference in New Issue