Fixed #28856 -- Fixed a regression in caching of a GenericForeignKey pointing to a MTI model.
Regression in b9f8635f58
.
This commit is contained in:
parent
f0a68c2511
commit
e50add6ca1
|
@ -872,6 +872,9 @@ class ForeignKey(ForeignObject):
|
|||
kwargs['to_field'] = self.remote_field.field_name
|
||||
return name, path, args, kwargs
|
||||
|
||||
def to_python(self, value):
|
||||
return self.target_field.to_python(value)
|
||||
|
||||
@property
|
||||
def target_field(self):
|
||||
return self.foreign_related_fields[0]
|
||||
|
|
|
@ -27,3 +27,6 @@ Bugfixes
|
|||
|
||||
* Made query lookups for ``CICharField``, ``CIEmailField``, and ``CITextField``
|
||||
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)
|
||||
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):
|
||||
"""
|
||||
SQL query parameters for generic relations are properly
|
||||
|
|
|
@ -93,3 +93,13 @@ class ForeignKeyTests(TestCase):
|
|||
|
||||
assert_app_model_resolved('model_fields')
|
||||
assert_app_model_resolved('tests')
|
||||
|
||||
@isolate_apps('model_fields')
|
||||
def test_to_python(self):
|
||||
class Foo(models.Model):
|
||||
pass
|
||||
|
||||
class Bar(models.Model):
|
||||
fk = models.ForeignKey(Foo, models.CASCADE)
|
||||
|
||||
self.assertEqual(Bar._meta.get_field('fk').to_python('1'), 1)
|
||||
|
|
|
@ -29,12 +29,6 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
|
|||
</object>
|
||||
</django-objects>""" # NOQA
|
||||
|
||||
@staticmethod
|
||||
def _comparison_value(value):
|
||||
# The XML serializer handles everything as strings, so comparisons
|
||||
# need to be performed on the stringified value
|
||||
return str(value)
|
||||
|
||||
@staticmethod
|
||||
def _validate_output(serial_str):
|
||||
try:
|
||||
|
|
|
@ -90,10 +90,6 @@ class SerializerRegistrationTests(SimpleTestCase):
|
|||
class SerializersTestBase:
|
||||
serializer_name = None # Set by subclasses to the serialization format name
|
||||
|
||||
@staticmethod
|
||||
def _comparison_value(value):
|
||||
return value
|
||||
|
||||
def setUp(self):
|
||||
sports = Category.objects.create(name="Sports")
|
||||
music = Category.objects.create(name="Music")
|
||||
|
@ -193,7 +189,7 @@ class SerializersTestBase:
|
|||
self.assertFalse(self._get_field_values(serial_str, 'author'))
|
||||
|
||||
for obj in serializers.deserialize(self.serializer_name, serial_str):
|
||||
self.assertEqual(obj.object.pk, self._comparison_value(self.joe.pk))
|
||||
self.assertEqual(obj.object.pk, self.joe.pk)
|
||||
|
||||
def test_serialize_field_subset(self):
|
||||
"""Output can be restricted to a subset of fields"""
|
||||
|
|
Loading…
Reference in New Issue