Ticket #34816: gfk-crash.patch

File gfk-crash.patch, 927 bytes (added by Richard Laager, 13 months ago)
  • django/contrib/contenttypes/fields.py

    diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
    index 35fcd0d908..e984fb5375 100644
    a b class GenericForeignKey(FieldCacheMixin):  
    242242            ct_match = (
    243243                ct_id == self.get_content_type(obj=rel_obj, using=instance._state.db).id
    244244            )
    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
    250250        if ct_id is not None:
    251251            ct = self.get_content_type(id=ct_id, using=instance._state.db)
    252252            try:
Back to Top