mirror of
https://github.com/django/django.git
synced 2025-11-01 20:31:40 +00:00
Fixed #21563 -- Single related object descriptors should work with hasattr.
Thanks to Aymeric Augustin for the review and Trac alias monkut for the report.
This commit is contained in:
parent
c7c647419c
commit
75924cfa6d
3 changed files with 45 additions and 7 deletions
|
|
@ -33,5 +33,14 @@ class ReverseSingleRelatedTests(TestCase):
|
|||
# of the "bare" queryset. Usually you'd define this as a property on the class,
|
||||
# but this approximates that in a way that's easier in tests.
|
||||
Source.objects.use_for_related_fields = True
|
||||
private_item = Item.objects.get(pk=private_item.pk)
|
||||
self.assertRaises(Source.DoesNotExist, lambda: private_item.source)
|
||||
try:
|
||||
private_item = Item.objects.get(pk=private_item.pk)
|
||||
self.assertRaises(Source.DoesNotExist, lambda: private_item.source)
|
||||
finally:
|
||||
Source.objects.use_for_related_fields = False
|
||||
|
||||
def test_hasattr_single_related(self):
|
||||
# The exception raised on attribute access when a related object
|
||||
# doesn't exist should be an instance of a subclass of `AttributeError`
|
||||
# refs #21563
|
||||
self.assertFalse(hasattr(Item(), 'source'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue