﻿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
11256	Fail loudly and clearly when an Annotation alias matches a field name.	donspaulding		"Continued from [http://groups.google.com/group/django-users/browse_thread/thread/b1ef13c597b6dd15 a django-users thread]

Given the following two models:

{{{
class Author(models.Model):
  last_updated = models.DateField()

class Book(models.Model):
  author = models.ForeignKey(Author, related_name='books')
  pubdate = models.DateField()
}}}

The following annotation query will produce unexpected results:

{{{
authors = Author.objects.annotate(last_updated=Max('books__pubdate'))
}}}

And it may not raise an error until you combine it with other parts of the queryset api, like order_by:

{{{
authors = Author.objects.annotate(last_updated=Max('books__pubdate')).order_by('last_updated')
}}}

While it's true that these invalid queries are the developer's fault, it's not at all obvious what's gone wrong.  Unless there is some valid case for clobbering your own namespace, I suggest that instead of leaving this behavior defined by the particular DB and query, an Exception be raised to let the developer know they've made a mistake before it hits the SQL level.
"		closed	Database layer (models, ORM)	dev		fixed			Ready for checkin	1	0	0	0	0	0
