Commit 6d17020c authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #10250 -- Added a regression test to ensure that GROUP BY statements are...

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
parent 5eccc596
Loading
Loading
Loading
Loading
+28 −42
Original line number Diff line number Diff line
@@ -44,17 +44,7 @@ class Store(models.Model):
    def __unicode__(self):
        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)

# Tests on 'aggergate'
# Tests on 'aggregate'
# Different backends and numbers.
__test__ = {'API_TESTS': """
>>> 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]
# 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
>>> 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'}]
+47 −31
Original line number Diff line number Diff line
@@ -48,7 +48,16 @@ class Store(models.Model):
    def __unicode__(self):
        return self.name

#Extra does not play well with values. Modify the tests if/when this is fixed.
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)

__test__ = {'API_TESTS': """
>>> from django.core import management
>>> 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')
[{'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
>>> Book.objects.filter(id__in=[]).count()
0