#17602: Django serializer does unnecessary db queries -------------------------------+-------------------- Reporter: anuraguniyal | Owner: nobody Type: Bug | Status: new Component: Uncategorized | Version: 1.3 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- When django serializes object, to get the foreign key id referenced in object it queries the db instead of just using the id e.g.
{{{#!python class QBAccount(CompanyModel): company = models.ForeignKey(Company) >>> from deretoapp.models import QBAccount >>> import logging >>> l = logging.getLogger('django.db.backends') >>> l.setLevel(logging.DEBUG) >>> l.addHandler(logging.StreamHandler()) >>> a = QBAccount.allobjects.all()[0] >>> from django.core import serializers >>> serializers.serialize('python', [a]) (0.000) SELECT `deretoapp_company`.`id`, ... FROM `deretoapp_company` WHERE `deretoapp_company`.`id` = 45995613-adeb-488f-9556-d69e856abe5f ; args=(u'45995613-adeb-488f-9556-d69e856abe5f',) [{'pk': u'3de881eb-8409-4089-8de8-6e24f7281f37', 'model': u'deretoapp.qbaccount', 'fields': {... 'company': u'45995613-adeb- 488f-9556-d69e856abe5f' ....}}] }}} Here db query after `serializers.serialize` is not needed because compay id could have been obtained directly by `a.company_id`, and query itself shows id is being passed to db to get the id, it looks like problem is because `a.company.id` is a db query which in ideal world also should not happen. -- Ticket URL: <https://code.djangoproject.com/ticket/17602> 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 post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.