#29078: Serializer handle_m2m_field should honour any previous prefetch
------------------------------------------------+------------------------
Reporter: xx396 | Owner: nobody
Type: Bug | Status: new
Component: Core (Serialization) | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
Example:
from django.contrib.auth.models import Group
from django.core import serializers
groups = Group.objects.prefetch_related('permissions__content_type').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()
self._current[field.name] = [
m2m_value(related) for related in getattr(obj,
field.name).iterator()
]
--
Ticket URL: <https://code.djangoproject.com/ticket/29078>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.fa19b8f6c56e17346658228af86d9c28%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.