Author: brosner
Date: 2008-07-17 15:12:21 -0500 (Thu, 17 Jul 2008)
New Revision: 7944
Modified:
django/branches/newforms-admin/
django/branches/newforms-admin/django/db/models/query.py
django/branches/newforms-admin/django/test/utils.py
django/branches/newforms-admin/tests/regressiontests/admin_scripts/tests.py
django/branches/newforms-admin/tests/regressiontests/queries/models.py
Log:
newforms-admin: Merged from trunk up to [7941].
Property changes on: django/branches/newforms-admin
___________________________________________________________________
Name: svnmerge-integrated
-
/django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7936
+
/django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7943
Modified: django/branches/newforms-admin/django/db/models/query.py
===================================================================
--- django/branches/newforms-admin/django/db/models/query.py 2008-07-17
16:48:27 UTC (rev 7943)
+++ django/branches/newforms-admin/django/db/models/query.py 2008-07-17
20:12:21 UTC (rev 7944)
@@ -280,11 +280,10 @@
Performs a SELECT COUNT() and returns the number of records as an
integer.
- If the QuerySet is already cached (i.e. self._result_cache is set) this
- simply returns the length of the cached results set to avoid multiple
- SELECT COUNT(*) calls.
+ If the QuerySet is already fully cached this simply returns the length
+ of the cached results set to avoid multiple SELECT COUNT(*) calls.
"""
- if self._result_cache is not None:
+ if self._result_cache is not None and not self._iter:
return len(self._result_cache)
return self.query.get_count()
Modified: django/branches/newforms-admin/django/test/utils.py
===================================================================
--- django/branches/newforms-admin/django/test/utils.py 2008-07-17 16:48:27 UTC
(rev 7943)
+++ django/branches/newforms-admin/django/test/utils.py 2008-07-17 20:12:21 UTC
(rev 7944)
@@ -74,7 +74,10 @@
def _set_autocommit(connection):
"Make sure a connection is in autocommit mode."
if hasattr(connection.connection, "autocommit"):
- connection.connection.autocommit(True)
+ if callable(connection.connection.autocommit):
+ connection.connection.autocommit(True)
+ else:
+ connection.connection.autocommit = True
elif hasattr(connection.connection, "set_isolation_level"):
connection.connection.set_isolation_level(0)
Modified:
django/branches/newforms-admin/tests/regressiontests/admin_scripts/tests.py
===================================================================
--- django/branches/newforms-admin/tests/regressiontests/admin_scripts/tests.py
2008-07-17 16:48:27 UTC (rev 7943)
+++ django/branches/newforms-admin/tests/regressiontests/admin_scripts/tests.py
2008-07-17 20:12:21 UTC (rev 7944)
@@ -108,7 +108,7 @@
self.assertEquals(len(stream), 0, "Stream should be empty: actually
contains '%s'" % stream)
def assertOutput(self, stream, msg):
"Utility assertion: assert that the given message exists in the output"
- self.assertTrue(msg in stream, "'%s' does not match actual output text
'%s'" % (msg, stream))
+ self.failUnless(msg in stream, "'%s' does not match actual output text
'%s'" % (msg, stream))
##########################################################################
# DJANGO ADMIN TESTS
Modified: django/branches/newforms-admin/tests/regressiontests/queries/models.py
===================================================================
--- django/branches/newforms-admin/tests/regressiontests/queries/models.py
2008-07-17 16:48:27 UTC (rev 7943)
+++ django/branches/newforms-admin/tests/regressiontests/queries/models.py
2008-07-17 20:12:21 UTC (rev 7944)
@@ -4,6 +4,7 @@
import datetime
import pickle
+import sys
from django.db import models
from django.db.models.query import Q, ITER_CHUNK_SIZE
@@ -483,23 +484,6 @@
>>> Cover.objects.all()
[<Cover: first>, <Cover: second>]
-# If you're not careful, it's possible to introduce infinite loops via default
-# ordering on foreign keys in a cycle. We detect that.
->>> LoopX.objects.all()
-Traceback (most recent call last):
-...
-FieldError: Infinite loop caused by ordering.
-
->>> LoopZ.objects.all()
-Traceback (most recent call last):
-...
-FieldError: Infinite loop caused by ordering.
-
-# ... but you can still order in a non-recursive fashion amongst linked fields
-# (the previous test failed because the default ordering was recursive).
->>> LoopX.objects.all().order_by('y__x__y__x__id')
-[]
-
# If the remote model does not have a default ordering, we order by its 'id'
# field.
>>> Item.objects.order_by('creator', 'name')
@@ -830,5 +814,37 @@
... obj.save()
... if i > 10: break
+Bug #7759 -- count should work with a partially read result set.
+>>> count = Number.objects.count()
+>>> qs = Number.objects.all()
+>>> for obj in qs:
+... qs.count() == count
+... break
+True
+
"""}
+# In Python 2.3, exceptions raised in __len__ are swallowed (Python issue
+# 1242657), so these cases return an empty list, rather than raising an
+# exception. Not a lot we can do about that, unfortunately, due to the way
+# Python handles list() calls internally. Thus, we skip the tests for Python
+# 2.3.
+if sys.version_info >= (2, 4):
+ __test__["API_TESTS"] += """
+# If you're not careful, it's possible to introduce infinite loops via default
+# ordering on foreign keys in a cycle. We detect that.
+>>> LoopX.objects.all()
+Traceback (most recent call last):
+...
+FieldError: Infinite loop caused by ordering.
+
+>>> LoopZ.objects.all()
+Traceback (most recent call last):
+...
+FieldError: Infinite loop caused by ordering.
+
+# ... but you can still order in a non-recursive fashion amongst linked fields
+# (the previous test failed because the default ordering was recursive).
+>>> LoopX.objects.all().order_by('y__x__y__x__id')
+[]
+"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---