﻿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
19087	Annotate() followed by exclude() raises an exception	Ivan Virabyan	Anssi Kääriäinen	"
{{{
class Post(models.Model):
     author = models.ForeignKey(User)

>>>print Post.objects.values('author').annotate(n=Count('pk')).exclude(author=1).query
  ...
  File ""django/django/db/backends/sqlite3/base.py"", line 157, in quote_name
    if name.startswith('""') and name.endswith('""'):
AttributeError: 'NoneType' object has no attribute 'startswith'
}}}

This works fine in django 1.4

I tried to investigate the bug, and found that it tries to join the `user` table ({{{db/models/sql/query.py:1190}}}), whereas in django 1.4 it doesn't

If I swap exclude() and annotate(), it works:
{{{ Post.objects.values('author').exclude(author=1).annotate(n=Count('pk')) }}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
