﻿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
10955	`select_related()` doesn't work with proxy models.	Tai Lee	Jacob	"I get a traceback if I call `get()` on a queryset for a proxy model which is using `select_related()`, or simply no objects if I try to access the queryset itself.

{{{
# models

class Country(models.Model):
	name = models.CharField(max_length=50, unique=True)

class State(models.Model):
	name = models.CharField(max_length=50)
	country = models.ForeignKey(Country)

	def __unicode__(self):
		return self.name

class StateProxy(State):
	class Meta:
		proxy = True

# interactive shell

>>> country = Country.objects.create(name='Australia')
>>> state = State.objects.create(name='New South Wales', country=country)

>>> State.objects.select_related()
[<State: New South Wales>]

>>> StateProxy.objects.select_related()
[]

# should have got [<State: New South Wales>]

>>> StateProxy.objects.get(name='New South Wales')
<StateProxy: New South Wales>

>>> StateProxy.objects.select_related().get(name='New South Wales')
Traceback (most recent call last):
  File ""<console>"", line 1, in ?
  File ""/path/to/django/db/models/manager.py"", line 120, in get
    return self.get_query_set().get(*args, **kwargs)
  File ""/path/to/django/db/models/query.py"", line 269, in get
    num = len(clone)
  File ""/path/to/django/db/models/query.py"", line 68, in __len__
    self._result_cache = list(self.iterator())
  File ""/path/to/django/db/models/query.py"", line 207, in iterator
    for row in self.query.results_iter():
  File ""/path/to/django/db/models/sql/query.py"", line 276, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""/path/to/django/db/models/sql/query.py"", line 2301, in execute_sql
    sql, params = self.as_sql()
  File ""/path/to/django/db/models/sql/query.py"", line 384, in as_sql
    self.pre_sql_setup()
  File ""/path/to/django/db/models/sql/query.py"", line 571, in pre_sql_setup
    self.fill_related_selections()
  File ""/path/to/django/db/models/sql/query.py"", line 1361, in fill_related_selections
    lhs_col = int_opts.parents[int_model].column
AttributeError: 'NoneType' object has no attribute 'column'

# should have got <StateProxy: New South Wales>
}}}
"		closed	Database layer (models, ORM)	dev		fixed	proxy model select_related	Armin Ronacher	Unreviewed	1	0	0	0	0	0
