Skip to content

v2.2.1: Fix recursive fetch depth for ManyToOneRel #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix recursive fetch depth for ManyToOneRel
  • Loading branch information
Archmonger committed Jan 2, 2023
commit 9226f683a70cb1f6f85c866e1cacf027376a6575
9 changes: 5 additions & 4 deletions src/django_idom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,16 @@ def django_query_postprocessor(

elif many_to_many and isinstance(field, ManyToManyField):
prefetch_fields.append(field.name)

if prefetch_fields:
prefetch_related_objects([data], *prefetch_fields)
for field_str in prefetch_fields:
django_query_postprocessor(
getattr(data, field.name).get_queryset(),
getattr(data, field_str).get_queryset(),
many_to_many=many_to_many,
many_to_one=many_to_one,
)

if prefetch_fields:
prefetch_related_objects([data], *prefetch_fields)

# Unrecognized type
else:
raise TypeError(
Expand Down