#24764: Using 'startswith' field lookup with F objects causes AttributeError
----------------------------------------------+--------------------
     Reporter:  Ernest0x                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.7
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/24764>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.6a98d2bd16a1f73fa2fc519447919586%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to