mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Fixes #14512: Omit unused queryset annotations for REST API requests using brief mode
This commit is contained in:
parent
69bf1472d2
commit
5508e125ba
@ -56,8 +56,15 @@ class BriefModeMixin:
|
|||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset()
|
||||||
|
|
||||||
# If using brief mode, clear all prefetches from the queryset and append only brief_prefetch_fields (if any)
|
|
||||||
if self.brief:
|
if self.brief:
|
||||||
|
serializer_class = self.get_serializer_class()
|
||||||
|
|
||||||
|
# Clear any annotations for fields not present on the nested serializer
|
||||||
|
for annotation in list(qs.query.annotations.keys()):
|
||||||
|
if annotation not in serializer_class().fields:
|
||||||
|
qs.query.annotations.pop(annotation)
|
||||||
|
|
||||||
|
# Clear any prefetches from the queryset and append only brief_prefetch_fields (if any)
|
||||||
return qs.prefetch_related(None).prefetch_related(*self.brief_prefetch_fields)
|
return qs.prefetch_related(None).prefetch_related(*self.brief_prefetch_fields)
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
Loading…
Reference in New Issue
Block a user