1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[1.2.X] 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. Backport of [14715].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14716 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2010-11-26 14:28:27 +00:00
parent c8e9d35e5c
commit 56dc22d64c
6 changed files with 66 additions and 21 deletions

View File

@@ -1088,11 +1088,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(
@@ -1278,15 +1279,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")),
@@ -1296,7 +1297,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.assertTrue(q1 is not q1.all())
class GeneratorExpressionTests(TestCase):
@@ -1447,6 +1448,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)
@@ -1472,8 +1483,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>']