summaryrefslogtreecommitdiff
path: root/django/contrib/contenttypes/fields.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-09-07 08:16:21 -0400
committerGitHub <noreply@github.com>2017-09-07 08:16:21 -0400
commit6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch)
tree1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/contrib/contenttypes/fields.py
parent8b2515a450ef376b9205029090af0a79c8341bd7 (diff)
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda because try/except performs better.
Diffstat (limited to 'django/contrib/contenttypes/fields.py')
-rw-r--r--django/contrib/contenttypes/fields.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
index 0884089d92..21367c4195 100644
--- a/django/contrib/contenttypes/fields.py
+++ b/django/contrib/contenttypes/fields.py
@@ -1,5 +1,4 @@
from collections import defaultdict
-from contextlib import suppress
from django.contrib.contenttypes.models import ContentType
from django.core import checks
@@ -237,8 +236,10 @@ class GenericForeignKey(FieldCacheMixin):
rel_obj = None
if ct_id is not None:
ct = self.get_content_type(id=ct_id, using=instance._state.db)
- with suppress(ObjectDoesNotExist):
+ try:
rel_obj = ct.get_object_for_this_type(pk=pk_val)
+ except ObjectDoesNotExist:
+ pass
self.set_cached_value(instance, rel_obj)
return rel_obj