id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux
15904,render_comment_form executes unnecessary query for object,Stefan Wehrmeyer,Stefan Wehrmeyer,"The template tag render_comment_form when given an object like this:
{{{
{% render_comment_form for obj %}
}}}
will retrieve obj from the database via content type and pk even though it is already present in the rendering context.
Details:
The problem is in django.contrib.comments.templatetags.comments in line [http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templatetags/comments.py#L127]
The context already contains the object, but get_form ignores that and hits the database via get_object_for_this_type. This is unnecessary and especially bad when you render multiple comment forms for different objects on one page.
I attached a patch that also includes a simple test.",Cleanup/optimization,closed,contrib.comments,1.3,Normal,fixed,,,Ready for checkin,1,0,0,0,1,