Kaydet (Commit) c9a96075 authored tarafından Anssi Kääriäinen's avatar Anssi Kääriäinen

Fixed #20378 -- regression in GenericRelation on abstract model

When a GenericRelation was defined on abstract model, queries on childs
of the abstract model didn't work. The problem was in the way fields and
in particular field.rel was copied from models to their children.

The regression was likely caused by #19385. Thanks to Gavin Wahl for
spotting the regression.
üst d9d24c45
......@@ -157,6 +157,8 @@ class Field(object):
obj = copy.copy(self)
if self.rel:
obj.rel = copy.copy(self.rel)
if hasattr(self.rel, 'field') and self.rel.field is self:
obj.rel.field = obj
memodict[id(self)] = obj
return obj
......
......@@ -122,3 +122,12 @@ class Tag(models.Model):
class Board(models.Model):
name = models.CharField(primary_key=True, max_length=15)
class HasLinks(models.Model):
links = generic.GenericRelation(Link)
class Meta:
abstract = True
class HasLinkThing(HasLinks):
pass
......@@ -4,7 +4,7 @@ from django.test import TestCase, skipIfDBFeature
from .models import (Address, Place, Restaurant, Link, CharLink, TextLink,
Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company,
Developer, Team, Guild, Tag, Board)
Developer, Team, Guild, Tag, Board, HasLinkThing)
class GenericRelationTests(TestCase):
......@@ -135,3 +135,21 @@ class GenericRelationTests(TestCase):
b1 = Board.objects.create(name='')
tag = Tag(label='VP', content_object=b1)
tag.save()
def test_ticket_20378(self):
hs1 = HasLinkThing.objects.create()
hs2 = HasLinkThing.objects.create()
l1 = Link.objects.create(content_object=hs1)
l2 = Link.objects.create(content_object=hs2)
self.assertQuerysetEqual(
HasLinkThing.objects.filter(links=l1),
[hs1], lambda x: x)
self.assertQuerysetEqual(
HasLinkThing.objects.filter(links=l2),
[hs2], lambda x: x)
self.assertQuerysetEqual(
HasLinkThing.objects.exclude(links=l2),
[hs1], lambda x: x)
self.assertQuerysetEqual(
HasLinkThing.objects.exclude(links=l1),
[hs2], lambda x: x)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment