﻿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
12890	extra() tables included twice do not generate aliases	Ilya Semenov	daveycrockett	"The documentation at http://docs.djangoproject.com/en/1.1/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none says: ""When you add extra tables via the tables parameter, Django assumes you want that table included an extra time, if it is already included. That creates a problem, since the table name will then be given an alias.""

That is not true even for simple cases:
{{{
#!python
print User.objects\
   .extra(tables=['auth_user_group'], where=['auth_user.ud=auth_user_group.user_id'])\
   .extra(tables=['auth_user_group'], where=['auth_user.ud=auth_user_group.user_id']).all()
# crashes with OperationalError(1066, ""Not unique table/alias: 'auth_user_group'"")
}}}

This is a real-life example (with different models, of course) from my project. I have to run an extra() query against the same table ''twice'' to achieve the double filtration, but it's not working and doesn't even allow me to specify the aliases manually. A usual double filter() trick would probably work but it is also broken due to #12885."	Bug	closed	Database layer (models, ORM)	1.3	Normal	wontfix	QuerySet.extra	daveycrockett michael@…	Accepted	1	0	1	0	0	0
