1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #16055 -- Fixed crash when filtering against char/text GenericRelation relation on PostgreSQL.

This commit is contained in:
David Wobrock
2023-04-18 10:19:06 +02:00
committed by Mariusz Felisiak
parent 594fcc2b74
commit 9bbf97bcdb
11 changed files with 117 additions and 13 deletions

View File

@@ -64,12 +64,14 @@ class CharLink(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.CharField(max_length=100)
content_object = GenericForeignKey()
value = models.CharField(max_length=250)
class TextLink(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.TextField()
content_object = GenericForeignKey()
value = models.CharField(max_length=250)
class OddRelation1(models.Model):

View File

@@ -72,6 +72,20 @@ class GenericRelationTests(TestCase):
TextLink.objects.create(content_object=oddrel)
oddrel.delete()
def test_charlink_filter(self):
oddrel = OddRelation1.objects.create(name="clink")
CharLink.objects.create(content_object=oddrel, value="value")
self.assertSequenceEqual(
OddRelation1.objects.filter(clinks__value="value"), [oddrel]
)
def test_textlink_filter(self):
oddrel = OddRelation2.objects.create(name="clink")
TextLink.objects.create(content_object=oddrel, value="value")
self.assertSequenceEqual(
OddRelation2.objects.filter(tlinks__value="value"), [oddrel]
)
def test_coerce_object_id_remote_field_cache_persistence(self):
restaurant = Restaurant.objects.create()
CharLink.objects.create(content_object=restaurant)