1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

[1.5.x] Fixed #20278 -- ensured .get() exceptions do not recurse infinitely

A regression caused by d5b93d3281 made .get() error
reporting recurse infinitely on certain rare conditions. Fixed this by
not trying to print the given lookup kwargs.

Backpatch of 266c0bb23e
This commit is contained in:
Anssi Kääriäinen
2013-05-20 18:45:24 +03:00
parent 367089a846
commit 0eddedf7db
3 changed files with 21 additions and 20 deletions

View File

@@ -8,7 +8,7 @@ from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils import six
from django.utils.translation import ugettext_lazy
from .models import Article
from .models import Article, SelfRef
class ModelTest(TestCase):
@@ -84,23 +84,14 @@ class ModelTest(TestCase):
# parameters don't match any object.
six.assertRaisesRegex(self,
ObjectDoesNotExist,
"Article matching query does not exist. Lookup parameters were "
"{'id__exact': 2000}",
"Article matching query does not exist.",
Article.objects.get,
id__exact=2000,
)
# To avoid dict-ordering related errors check only one lookup
# in single assert.
six.assertRaisesRegex(self,
self.assertRaises(
ObjectDoesNotExist,
".*'pub_date__year': 2005.*",
Article.objects.get,
pub_date__year=2005,
pub_date__month=8,
)
six.assertRaisesRegex(self,
ObjectDoesNotExist,
".*'pub_date__month': 8.*",
Article.objects.get,
pub_date__year=2005,
pub_date__month=8,
@@ -108,8 +99,7 @@ class ModelTest(TestCase):
six.assertRaisesRegex(self,
ObjectDoesNotExist,
"Article matching query does not exist. Lookup parameters were "
"{'pub_date__week_day': 6}",
"Article matching query does not exist.",
Article.objects.get,
pub_date__week_day=6,
)
@@ -639,3 +629,8 @@ class ModelTest(TestCase):
Article.objects.bulk_create([Article(headline=lazy, pub_date=datetime.now())])
article = Article.objects.get()
self.assertEqual(article.headline, notlazy)
def test_ticket_20278(self):
sr = SelfRef.objects.create()
with self.assertRaises(ObjectDoesNotExist):
SelfRef.objects.get(selfref=sr)