kopia lustrzana https://github.com/wagtail/wagtail
Fix alias() not compatible with specific()
Fixes #11285 # Conflicts: # CHANGELOG.txt # docs/releases/6.0.mdpull/11297/head
rodzic
8e5ab4aeb4
commit
c26e0326a2
|
@ -515,7 +515,7 @@ class SpecificIterable(BaseIterable):
|
|||
in the same order, with any annotations intact.
|
||||
"""
|
||||
qs = self.queryset
|
||||
annotation_aliases = qs.query.annotations.keys()
|
||||
annotation_aliases = qs.query.annotation_select
|
||||
values_qs = qs.values("pk", "content_type", *annotation_aliases)
|
||||
|
||||
# Gather items in batches to reduce peak memory usage
|
||||
|
|
|
@ -920,6 +920,25 @@ class TestSpecificQuery(WagtailTestUtils, TestCase):
|
|||
self.assertEqual(results.first().subscribers_count, 1)
|
||||
self.assertEqual(results.last().subscribers_count, 1)
|
||||
|
||||
def test_specific_query_with_alias(self):
|
||||
"""
|
||||
Ensure alias() works with specific() queries.
|
||||
See https://github.com/wagtail/wagtail/issues/11285 for more details
|
||||
"""
|
||||
|
||||
pages = Page.objects.live()
|
||||
user = self.create_test_user()
|
||||
pages.first().subscribers.create(user=user, comment_notifications=False)
|
||||
pages.last().subscribers.create(user=user, comment_notifications=False)
|
||||
|
||||
# This would previously fail as described in #11285.
|
||||
iter(
|
||||
Page.objects.live()
|
||||
.specific()
|
||||
.alias(subscribers_count=Count("subscribers"))
|
||||
.order_by("subscribers_count")
|
||||
)
|
||||
|
||||
def test_specific_gracefully_handles_missing_models(self):
|
||||
# 3567 - PageQuerySet.specific should gracefully handle pages whose class definition
|
||||
# is missing, by keeping them as basic Page instances.
|
||||
|
|
Ładowanie…
Reference in New Issue