Skip to content

Commit

Permalink
Fixed #26261 -- Fixed queryset crash when excluding reverse GenericRe…
Browse files Browse the repository at this point in the history
…lation.

Thanks Amir Hadi for the report.
  • Loading branch information
gorodovoy9000 authored and felixxm committed Nov 18, 2022
1 parent 51faf4b commit 04b1502
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/contrib/contenttypes/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def get_reverse_path_info(self, filtered_relation=None):
to_opts=opts,
target_fields=(opts.pk,),
join_field=self,
m2m=not self.unique,
m2m=False,
direct=False,
filtered_relation=filtered_relation,
)
Expand Down
10 changes: 10 additions & 0 deletions tests/generic_relations_regress/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,13 @@ def test_generic_reverse_relation_with_abc(self):
thing = HasLinkThing.objects.create()
link = Link.objects.create(content_object=thing)
self.assertCountEqual(link.targets.all(), [thing])

def test_generic_reverse_relation_exclude_filter(self):
place1 = Place.objects.create(name="Test Place 1")
place2 = Place.objects.create(name="Test Place 2")
Link.objects.create(content_object=place1)
link2 = Link.objects.create(content_object=place2)
qs = Link.objects.filter(~Q(places__name="Test Place 1"))
self.assertSequenceEqual(qs, [link2])
qs = Link.objects.exclude(places__name="Test Place 1")
self.assertSequenceEqual(qs, [link2])

0 comments on commit 04b1502

Please sign in to comment.