Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…nitely

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

Backpatch of 266c0bb
  • Loading branch information...
commit 0eddedf7db782a05e098c7024a9056aef7283b81 1 parent 367089a
@akaariai akaariai authored
View
10 django/db/models/query.py
@@ -384,13 +384,11 @@ def get(self, *args, **kwargs):
return clone._result_cache[0]
if not num:
raise self.model.DoesNotExist(
- "%s matching query does not exist. "
- "Lookup parameters were %s" %
- (self.model._meta.object_name, kwargs))
+ "%s matching query does not exist." %
+ self.model._meta.object_name)
raise self.model.MultipleObjectsReturned(
- "get() returned more than one %s -- it returned %s! "
- "Lookup parameters were %s" %
- (self.model._meta.object_name, num, kwargs))
+ "get() returned more than one %s -- it returned %s!" %
+ (self.model._meta.object_name, num))
def create(self, **kwargs):
"""
View
8 tests/modeltests/basic/models.py
@@ -18,3 +18,11 @@ class Meta:
def __str__(self):
return self.headline
+
+@python_2_unicode_compatible
+class SelfRef(models.Model):
+ selfref = models.ForeignKey('self', null=True, blank=True,
+ related_name='+')
+
+ def __str__(self):
+ return SelfRef.objects.get(selfref=self).pk
View
23 tests/modeltests/basic/tests.py
@@ -8,7 +8,7 @@
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 @@ def test_lookup(self):
# 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,
- ObjectDoesNotExist,
- ".*'pub_date__year': 2005.*",
- Article.objects.get,
- pub_date__year=2005,
- pub_date__month=8,
- )
- six.assertRaisesRegex(self,
+ self.assertRaises(
ObjectDoesNotExist,
- ".*'pub_date__month': 8.*",
Article.objects.get,
pub_date__year=2005,
pub_date__month=8,
@@ -108,8 +99,7 @@ def test_lookup(self):
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 @@ def test_create_relation_with_ugettext_lazy(self):
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)

0 comments on commit 0eddedf

Please sign in to comment.
Something went wrong with that request. Please try again.