﻿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
2351	MySQL syntax error on object.all().count(), when called from template	gumuz	Adrian Holovaty	"I have a blogpost model which is referenced by a Comment class. Thus, the Blogpost model has a comment_set attribute.

I gave the Blogpost model a method like this:

{{{
def comments(self):
    return self.comment_set.all()
}}}

When i access it from the shell and use the .count() method on the !QuerySet, everything is fine:

{{{
>>> from devlog.weblog.models import Post
>>> p = Post.objects.all()[4]
>>> p.comments()
[<Comment: gumuz - 2006-07-12 07:10:30>, <Comment: gumuz - 2006-07-12 07:09:56>]
>>> p.comments().count()
2L
}}}

When i do the same from my template:

{{{
{{ object.comments.count }}
}}}

I get the following error:

{{{
Exception Type:  	ProgrammingError
Exception Value: 	(1064, ""You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'count,1' at line 1"")
Exception Location: 	/usr/lib/python2.4/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 33
}}}

The length-filter works fine though:

{{{
{{ object.comments|length }}
}}}


"	defect	closed	Database layer (models, ORM)		normal	fixed			Accepted	1	0	1	0	0	0
