diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
index 35fcd0d908..e984fb5375 100644
a
|
b
|
class GenericForeignKey(FieldCacheMixin):
|
242 | 242 | ct_match = ( |
243 | 243 | ct_id == self.get_content_type(obj=rel_obj, using=instance._state.db).id |
244 | 244 | ) |
245 | | pk_match = rel_obj._meta.pk.to_python(pk_val) == rel_obj.pk |
246 | | if ct_match and pk_match: |
247 | | return rel_obj |
248 | | else: |
249 | | rel_obj = None |
| 245 | if ct_match: |
| 246 | pk_match = rel_obj._meta.pk.to_python(pk_val) == rel_obj.pk |
| 247 | if pk_match: |
| 248 | return rel_obj |
| 249 | rel_obj = None |
250 | 250 | if ct_id is not None: |
251 | 251 | ct = self.get_content_type(id=ct_id, using=instance._state.db) |
252 | 252 | try: |