Loading django/db/models/fields/related.py +5 −2 Original line number Diff line number Diff line Loading @@ -201,7 +201,9 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri setattr(rel_obj, self.related.field.get_cache_name(), instance) setattr(instance, self.cache_name, rel_obj) if rel_obj is None: raise self.related.model.DoesNotExist raise self.related.model.DoesNotExist("%s has no %s." % ( instance.__class__.__name__, self.related.get_accessor_name())) else: return rel_obj Loading Loading @@ -304,7 +306,8 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec setattr(rel_obj, self.field.related.get_cache_name(), instance) setattr(instance, self.cache_name, rel_obj) if rel_obj is None and not self.field.null: raise self.field.rel.to.DoesNotExist raise self.field.rel.to.DoesNotExist( "%s has no %s." % (self.field.model.__name__, self.field.name)) else: return rel_obj Loading docs/releases/1.6.txt +3 −0 Original line number Diff line number Diff line Loading @@ -277,6 +277,9 @@ Minor features a ``SuspiciousOperation`` reaches the WSGI handler to return an ``HttpResponseBadRequest``. * The :exc:`~django.core.exceptions.DoesNotExist` exception now includes a message indicating the name of the attribute used for the lookup. Backwards incompatible changes in 1.6 ===================================== Loading tests/foreign_object/tests.py +5 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,11 @@ class MultiColumnFKTests(TestCase): list(Article.objects.filter(active_translation__abstract=None)), [a1, a2]) def test_foreign_key_raises_informative_does_not_exist(self): referrer = ArticleTranslation() with self.assertRaisesMessage(Article.DoesNotExist, 'ArticleTranslation has no article'): referrer.article class FormsTests(TestCase): # ForeignObjects should not have any form fields, currently the user needs # to manually deal with the foreignobject relation. Loading tests/one_to_one/tests.py +2 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,8 @@ class OneToOneTests(TestCase): # A Place can access its restaurant, if available. self.assertEqual(repr(self.p1.restaurant), '<Restaurant: Demon Dogs the restaurant>') # p2 doesn't have an associated restaurant. self.assertRaises(Restaurant.DoesNotExist, getattr, self.p2, 'restaurant') with self.assertRaisesMessage(Restaurant.DoesNotExist, 'Place has no restaurant'): self.p2.restaurant def test_setter(self): # Set the place using assignment notation. Because place is the primary Loading Loading
django/db/models/fields/related.py +5 −2 Original line number Diff line number Diff line Loading @@ -201,7 +201,9 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri setattr(rel_obj, self.related.field.get_cache_name(), instance) setattr(instance, self.cache_name, rel_obj) if rel_obj is None: raise self.related.model.DoesNotExist raise self.related.model.DoesNotExist("%s has no %s." % ( instance.__class__.__name__, self.related.get_accessor_name())) else: return rel_obj Loading Loading @@ -304,7 +306,8 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec setattr(rel_obj, self.field.related.get_cache_name(), instance) setattr(instance, self.cache_name, rel_obj) if rel_obj is None and not self.field.null: raise self.field.rel.to.DoesNotExist raise self.field.rel.to.DoesNotExist( "%s has no %s." % (self.field.model.__name__, self.field.name)) else: return rel_obj Loading
docs/releases/1.6.txt +3 −0 Original line number Diff line number Diff line Loading @@ -277,6 +277,9 @@ Minor features a ``SuspiciousOperation`` reaches the WSGI handler to return an ``HttpResponseBadRequest``. * The :exc:`~django.core.exceptions.DoesNotExist` exception now includes a message indicating the name of the attribute used for the lookup. Backwards incompatible changes in 1.6 ===================================== Loading
tests/foreign_object/tests.py +5 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,11 @@ class MultiColumnFKTests(TestCase): list(Article.objects.filter(active_translation__abstract=None)), [a1, a2]) def test_foreign_key_raises_informative_does_not_exist(self): referrer = ArticleTranslation() with self.assertRaisesMessage(Article.DoesNotExist, 'ArticleTranslation has no article'): referrer.article class FormsTests(TestCase): # ForeignObjects should not have any form fields, currently the user needs # to manually deal with the foreignobject relation. Loading
tests/one_to_one/tests.py +2 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,8 @@ class OneToOneTests(TestCase): # A Place can access its restaurant, if available. self.assertEqual(repr(self.p1.restaurant), '<Restaurant: Demon Dogs the restaurant>') # p2 doesn't have an associated restaurant. self.assertRaises(Restaurant.DoesNotExist, getattr, self.p2, 'restaurant') with self.assertRaisesMessage(Restaurant.DoesNotExist, 'Place has no restaurant'): self.p2.restaurant def test_setter(self): # Set the place using assignment notation. Because place is the primary Loading