mirror of
https://github.com/django/django.git
synced 2025-06-16 00:49:12 +00:00
[1.11.x] Fixed #28856 -- Fixed a regression in caching of a GenericForeignKey pointing to a MTI model.
Regression in b9f8635f58ad743995cad2081b3dc395e55761e5. Backport of d31424fec1a3de9d281535c0503644a9d7b93c63 from stable/2.0.x
This commit is contained in:
parent
3545e84488
commit
f319e7abad
@ -230,9 +230,16 @@ class GenericForeignKey(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
rel_obj = None
|
rel_obj = None
|
||||||
else:
|
else:
|
||||||
if rel_obj and (ct_id != self.get_content_type(obj=rel_obj, using=instance._state.db).id or
|
if rel_obj:
|
||||||
rel_obj._meta.pk.to_python(pk_val) != rel_obj._get_pk_val()):
|
if ct_id != self.get_content_type(obj=rel_obj, using=instance._state.db).id:
|
||||||
rel_obj = None
|
rel_obj = None
|
||||||
|
else:
|
||||||
|
pk = rel_obj._meta.pk
|
||||||
|
# If the primary key is a remote field, use the referenced
|
||||||
|
# field's to_python().
|
||||||
|
pk_to_python = pk.target_field.to_python if pk.remote_field else pk.to_python
|
||||||
|
if pk_to_python(pk_val) != rel_obj._get_pk_val():
|
||||||
|
rel_obj = None
|
||||||
|
|
||||||
if rel_obj is not None:
|
if rel_obj is not None:
|
||||||
return rel_obj
|
return rel_obj
|
||||||
|
@ -27,3 +27,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Made query lookups for ``CICharField``, ``CIEmailField``, and ``CITextField``
|
* Made query lookups for ``CICharField``, ``CIEmailField``, and ``CITextField``
|
||||||
use a ``citext`` cast (:ticket:`28702`).
|
use a ``citext`` cast (:ticket:`28702`).
|
||||||
|
|
||||||
|
* Fixed a regression in caching of a ``GenericForeignKey`` when the referenced
|
||||||
|
model instance uses multi-table inheritance (:ticket:`28856`).
|
||||||
|
@ -48,6 +48,12 @@ class GenericRelationTests(TestCase):
|
|||||||
TextLink.objects.create(content_object=oddrel)
|
TextLink.objects.create(content_object=oddrel)
|
||||||
oddrel.delete()
|
oddrel.delete()
|
||||||
|
|
||||||
|
def test_coerce_object_id_remote_field_cache_persistence(self):
|
||||||
|
restaurant = Restaurant.objects.create()
|
||||||
|
CharLink.objects.create(content_object=restaurant)
|
||||||
|
charlink = CharLink.objects.latest('pk')
|
||||||
|
self.assertIs(charlink.content_object, charlink.content_object)
|
||||||
|
|
||||||
def test_q_object_or(self):
|
def test_q_object_or(self):
|
||||||
"""
|
"""
|
||||||
SQL query parameters for generic relations are properly
|
SQL query parameters for generic relations are properly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user