﻿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
24764	Using 'startswith' field lookup with F objects causes AttributeError	Petros Moisiadis	nobody	"In Django 1.7.8, when using ""startswith""  field lookup with F objects in the same query, the following AttributeError exception is raised:

{{{
>>> objects = MyObject.objects.filter(name__startswith=F('description'))
>>> objects
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py"", line 116, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py"", line 141, in __iter__
    self._fetch_all()
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py"", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/query.py"", line 265, in iterator
    for row in compiler.results_iter():
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py"", line 701, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py"", line 776, in execute_sql
    sql, params = self.as_sql()
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py"", line 110, in as_sql
    where, w_params = self.compile(self.query.where)
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py"", line 81, in compile
    return node.as_sql(self, self.connection)
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/where.py"", line 106, in as_sql
    sql, params = qn.compile(child)
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py"", line 81, in compile
    return node.as_sql(self, self.connection)
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/lookups.py"", line 152, in as_sql
    rhs_sql = self.get_rhs_op(connection, rhs_sql)
  File ""/path/to/virtualenv/lib/python3.4/site-packages/django/db/models/lookups.py"", line 258, in get_rhs_op
    return connection.pattern_ops[self.lookup_name] % rhs
AttributeError: 'DatabaseWrapper' object has no attribute 'pattern_ops'
}}}

The following (without the 'startswith' field lookup), however, works:
{{{
>>> objects = MyObject.objects.filter(name=F('description'))
>>> objects
[...]
}}}

Interestingly,  Django 1.8 does not have this bug."	Bug	closed	Database layer (models, ORM)	1.7	Normal	wontfix			Unreviewed	0	0	0	0	0	0
