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.
This commit is contained in:
parent
c9a96075fa
commit
266c0bb23e
|
@ -388,13 +388,11 @@ class QuerySet(object):
|
||||||
return clone._result_cache[0]
|
return clone._result_cache[0]
|
||||||
if not num:
|
if not num:
|
||||||
raise self.model.DoesNotExist(
|
raise self.model.DoesNotExist(
|
||||||
"%s matching query does not exist. "
|
"%s matching query does not exist." %
|
||||||
"Lookup parameters were %s" %
|
self.model._meta.object_name)
|
||||||
(self.model._meta.object_name, kwargs))
|
|
||||||
raise self.model.MultipleObjectsReturned(
|
raise self.model.MultipleObjectsReturned(
|
||||||
"get() returned more than one %s -- it returned %s! "
|
"get() returned more than one %s -- it returned %s!" %
|
||||||
"Lookup parameters were %s" %
|
(self.model._meta.object_name, num))
|
||||||
(self.model._meta.object_name, num, kwargs))
|
|
||||||
|
|
||||||
def create(self, **kwargs):
|
def create(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -18,3 +18,11 @@ class Article(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
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
|
||||||
|
|
|
@ -11,7 +11,7 @@ from django.test import TestCase, TransactionTestCase, skipIfDBFeature, skipUnle
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from .models import Article
|
from .models import Article, SelfRef
|
||||||
|
|
||||||
|
|
||||||
class ModelTest(TestCase):
|
class ModelTest(TestCase):
|
||||||
|
@ -87,23 +87,14 @@ class ModelTest(TestCase):
|
||||||
# parameters don't match any object.
|
# parameters don't match any object.
|
||||||
six.assertRaisesRegex(self,
|
six.assertRaisesRegex(self,
|
||||||
ObjectDoesNotExist,
|
ObjectDoesNotExist,
|
||||||
"Article matching query does not exist. Lookup parameters were "
|
"Article matching query does not exist.",
|
||||||
"{'id__exact': 2000}",
|
|
||||||
Article.objects.get,
|
Article.objects.get,
|
||||||
id__exact=2000,
|
id__exact=2000,
|
||||||
)
|
)
|
||||||
# To avoid dict-ordering related errors check only one lookup
|
# To avoid dict-ordering related errors check only one lookup
|
||||||
# in single assert.
|
# in single assert.
|
||||||
six.assertRaisesRegex(self,
|
self.assertRaises(
|
||||||
ObjectDoesNotExist,
|
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,
|
Article.objects.get,
|
||||||
pub_date__year=2005,
|
pub_date__year=2005,
|
||||||
pub_date__month=8,
|
pub_date__month=8,
|
||||||
|
@ -111,8 +102,7 @@ class ModelTest(TestCase):
|
||||||
|
|
||||||
six.assertRaisesRegex(self,
|
six.assertRaisesRegex(self,
|
||||||
ObjectDoesNotExist,
|
ObjectDoesNotExist,
|
||||||
"Article matching query does not exist. Lookup parameters were "
|
"Article matching query does not exist.",
|
||||||
"{'pub_date__week_day': 6}",
|
|
||||||
Article.objects.get,
|
Article.objects.get,
|
||||||
pub_date__week_day=6,
|
pub_date__week_day=6,
|
||||||
)
|
)
|
||||||
|
@ -689,6 +679,12 @@ class ModelTest(TestCase):
|
||||||
with self.assertNumQueries(0):
|
with self.assertNumQueries(0):
|
||||||
self.assertEqual(len(Article.objects.none().distinct('headline', 'pub_date')), 0)
|
self.assertEqual(len(Article.objects.none().distinct('headline', 'pub_date')), 0)
|
||||||
|
|
||||||
|
def test_ticket_20278(self):
|
||||||
|
sr = SelfRef.objects.create()
|
||||||
|
with self.assertRaises(ObjectDoesNotExist):
|
||||||
|
SelfRef.objects.get(selfref=sr)
|
||||||
|
|
||||||
|
|
||||||
class ConcurrentSaveTests(TransactionTestCase):
|
class ConcurrentSaveTests(TransactionTestCase):
|
||||||
@skipUnlessDBFeature('test_db_allows_multiple_connections')
|
@skipUnlessDBFeature('test_db_allows_multiple_connections')
|
||||||
def test_concurrent_delete_with_save(self):
|
def test_concurrent_delete_with_save(self):
|
||||||
|
|
Loading…
Reference in New Issue