Opened 6 years ago

Last modified 4 years ago

#29078 closed Cleanup/optimization

Serializer handle_m2m_field should honour any previous prefetch — at Version 1

Reported by: xx396 Owned by: nobody
Component: Core (Serialization) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by xx396)

Example:

from django.contrib.auth.models import Group
from django.core import serializers

groups = Group.objects.prefetch_related('permissions').all()
serializers.serialize('json', groups)

This will N+1 query the permissions as handle_m2m_field uses iterator() which bypasses any cache. Suggest serializers/python.py line 77 replaces iterator() with all()

Change History (1)

comment:1 by xx396, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top