You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using strawberry_django.field(annotate=...), any additional annotations added in get_queryset are removed. This makes it difficult to dynamically modify the queryset while keeping the annotation intact.
Reproduction Steps
Define a Strawberry Django type with an annotated field:
import strawberry
import strawberry_django
from django.db.models import Count, Q
from myapp.models import JobApplicationModel, JobModel
@strawberry_django.type(JobModel)
class JobType:
application_count: int = strawberry_django.field(
annotate=Count(
"job_applications",
filter=Q(job_applications__status=JobApplicationModel.Status.SUBMITTED),
distinct=True,
)
)
@classmethod
def get_queryset(cls, queryset, info):
return queryset.annotate(
another_annotation=Count("some_other_related_field")
)
The expected behavior is that application_count should persist, and another_annotation should be added in get_queryset.
However, when get_queryset runs, the another_annotation is removed.
System Information
Strawberry version (if applicable): 0.237.3
Strawberry Django version: 0.47.1
Additional Context
The text was updated successfully, but these errors were encountered:
That annotate parameter on strawberry_django.field gets added by the optimizer, and it will run after get_queryset
I'm wondering here if what you are seeing is get_queryset not running at all or something else
However, when get_queryset runs, the another_annotation is removed.
Just to be clean, you mean that when get_queryset runs, the application_count gets removed, right? Because get_queryset is what annotates another_annotation
Also, how have you seen that the annotation is not there? Have you gotten any errors or were you checking it during get_queryset or some other place?
Uh oh!
There was an error while loading. Please reload this page.
Describe the Bug
When using strawberry_django.field(annotate=...), any additional annotations added in get_queryset are removed. This makes it difficult to dynamically modify the queryset while keeping the annotation intact.
Reproduction Steps
System Information
Additional Context
The text was updated successfully, but these errors were encountered: