﻿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
21703	`exclude` query with `F` object across relationship fails	anonymous	nobody	"Given the following models..

{{{
#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  class Owner(models.Model):
    pass
 
 
class Thing(models.Model):
    owner = models.ForeignKey(Owner, related_name='things')
 
    date = models.DateField()
 
 
class Error(models.Model):
    owner = models.ForeignKey(Owner, related_name='errors')
 
    date = models.DateField()
 
  }}}
}}}

The following `exclude` query fails.

{{{
#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  >>> Error.objects.exclude(owner__things__date=F('date'))
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/query.py"", line 115, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/query.py"", line 140, in __iter__
    self._fetch_all()
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/query.py"", line 962, in _fetch_all
    self._result_cache = list(self.iterator())
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/query.py"", line 264, in iterator
    for row in compiler.results_iter():
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/sql/compiler.py"", line 681, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/models/sql/compiler.py"", line 762, in execute_sql
    cursor.execute(sql, params)
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/backends/utils.py"", line 77, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/backends/utils.py"", line 61, in execute
    return self.cursor.execute(sql, params)
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/utils.py"", line 93, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/backends/utils.py"", line 61, in execute
    return self.cursor.execute(sql, params)
  File ""/Users/foobar/python-environments/358426a27f281ff5/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py"", line 489, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: no such column: U1.id

  }}}
}}}


The same query using a `filter` works as expected.  This bug is present in `1.5.5`, `1.6.1` and `1.7.dev20131229181725`"	Bug	closed	Database layer (models, ORM)	1.6	Normal	fixed			Accepted	0	0	1	0	0	0
