Opened 7 years ago
Last modified 5 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 )
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()
Note:
See TracTickets
for help on using tickets.