Fixed a suite of errors in the ORM -- a) fixed calling values_list().values_list() and changing whether the results are flat, b) fixed an issue with fields on the left-hand side of what becomes the HAVING clause not being included in the GROUP BY clause, and c) fixed a bug with fields from values() calls not being included in the GROUP BY clause. This fixed the recent test failures under postgresql.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-11-26 14:24:08 +00:00
parent 3cbaf3c2b6
commit 678f626c24
6 changed files with 66 additions and 21 deletions

View file

@ -1093,11 +1093,12 @@ class Queries5Tests(TestCase):
# Extra tables used to crash SQL construction on the second use.
qs = Ranking.objects.extra(tables=['django_site'])
qs.query.get_compiler(qs.db).as_sql()
qs.query.get_compiler(qs.db).as_sql() # test passes if this doesn't raise an exception.
# test passes if this doesn't raise an exception.
qs.query.get_compiler(qs.db).as_sql()
def test_ticket9848(self):
# Make sure that updates which only filter on sub-tables don't inadvertently
# update the wrong records (bug #9848).
# Make sure that updates which only filter on sub-tables don't
# inadvertently update the wrong records (bug #9848).
# Make sure that the IDs from different tables don't happen to match.
self.assertQuerysetEqual(
@ -1283,15 +1284,15 @@ class Queries6Tests(TestCase):
)
# The annotation->tag link is single values and tag->children links is
# multi-valued. So we have to split the exclude filter in the middle and then
# optimise the inner query without losing results.
# multi-valued. So we have to split the exclude filter in the middle
# and then optimise the inner query without losing results.
self.assertQuerysetEqual(
Annotation.objects.exclude(tag__children__name="t2"),
['<Annotation: a2>']
)
# Nested queries are possible (although should be used with care, since they have
# performance problems on backends like MySQL.
# Nested queries are possible (although should be used with care, since
# they have performance problems on backends like MySQL.
self.assertQuerysetEqual(
Annotation.objects.filter(notes__in=Note.objects.filter(note="n1")),
@ -1301,7 +1302,7 @@ class Queries6Tests(TestCase):
def test_ticket3739(self):
# The all() method on querysets returns a copy of the queryset.
q1 = Tag.objects.order_by('name')
self.assertNotEqual(id(q1), id(q1.all()))
self.assertIsNot(q1, q1.all())
class GeneratorExpressionTests(TestCase):
@ -1452,6 +1453,16 @@ class EmptyQuerySetTests(TestCase):
)
class ValuesQuerysetTests(BaseQuerysetTest):
def test_flat_values_lits(self):
Number.objects.create(num=72)
qs = Number.objects.values_list("num")
qs = qs.values_list("num", flat=True)
self.assertValueQuerysetEqual(
qs, [72]
)
class WeirdQuerysetSlicingTests(BaseQuerysetTest):
def setUp(self):
Number.objects.create(num=1)
@ -1481,8 +1492,8 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest):
class EscapingTests(TestCase):
def test_ticket_7302(self):
# Reserved names are appropriately escaped
_ = ReservedName.objects.create(name='a',order=42)
ReservedName.objects.create(name='b',order=37)
_ = ReservedName.objects.create(name='a', order=42)
ReservedName.objects.create(name='b', order=37)
self.assertQuerysetEqual(
ReservedName.objects.all().order_by('order'),
['<ReservedName: b>', '<ReservedName: a>']