Skip to content

Commit 03aa282

Browse files
committed
Failing test for GenericRelation on an abstract model
When GenericRelation is defined on an abstract model, reverse joins fail.
1 parent 7476d96 commit 03aa282

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/generic_relations_regress/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
88
'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
9-
'Contact', 'Organization', 'Note', 'Company')
9+
'Contact', 'Organization', 'Note', 'Company', 'HasLinkThing')
1010

1111
@python_2_unicode_compatible
1212
class Link(models.Model):
@@ -122,3 +122,13 @@ class Tag(models.Model):
122122

123123
class Board(models.Model):
124124
name = models.CharField(primary_key=True, max_length=15)
125+
126+
127+
class HasLinks(models.Model):
128+
links = generic.GenericRelation(Link)
129+
130+
class Meta:
131+
abstract = True
132+
133+
class HasLinkThing(HasLinks):
134+
pass

tests/generic_relations_regress/tests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .models import (Address, Place, Restaurant, Link, CharLink, TextLink,
66
Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company,
7-
Developer, Team, Guild, Tag, Board)
7+
Developer, Team, Guild, Tag, Board, HasLinkThing)
88

99

1010
class GenericRelationTests(TestCase):
@@ -135,3 +135,13 @@ def test_gfk_to_model_with_empty_pk(self):
135135
b1 = Board.objects.create(name='')
136136
tag = Tag(label='VP', content_object=b1)
137137
tag.save()
138+
139+
def test_abstract_reverse_join(self):
140+
linked_thing = HasLinkThing.objects.create()
141+
link = Link.objects.create(
142+
content_object=linked_thing
143+
)
144+
145+
self.assertQuerysetEqual(HasLinkThing.objects.filter(links=link), [
146+
"<HasLinkThing: HasLinkThing object>",
147+
])

0 commit comments

Comments
 (0)