Skip to content

Commit

Permalink
Update strawberry_django/optimizer.py
Browse files Browse the repository at this point in the history
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
bellini666 and sourcery-ai[bot] authored Jul 13, 2024
1 parent 3ac223a commit 2bb9b1d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions strawberry_django/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,10 @@ def _get_hints_from_django_relation(

field_store = getattr(field, "store", None)
if field_store and field_store.prefetch_related:
# When we have a prefetch_related in the field, skip the optimization as
# it will probably be filtering/annotating the queryset differently, and doing
# it here would result in an extra unused query
# Skip optimization if 'prefetch_related' is present in the field's store.
# This is necessary because 'prefetch_related' likely modifies the queryset
# with filtering or annotating, making the optimization redundant and
# potentially causing an extra unused query.
return store

remote_field = model_field.remote_field
Expand Down

0 comments on commit 2bb9b1d

Please sign in to comment.