[PATCH] Fix AssertionError with empty WHERE clause

Bug #1307893 reported by Jean-Baptiste Quenot
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
New
Undecided
Unassigned

Bug Description

OpenERP from current 7.0 branch and all earlier 7.0 versions may crash with the following traceback when using some specific search expressions:

2014-04-15 07:57:09,032 4668 ERROR cmlid-test openerp.netsvc:
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 2372, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4931, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4757, in _where_calc
    e = expression.expression(cr, user, domain, self, context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 646, in __init__
    self.parse(cr, uid, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 845, in parse
    right_ids = relational_model.search(cr, uid, [(field_path[1], operator, right)], context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 2372, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4931, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4759, in _where_calc
    where_clause, where_params = e.to_sql()
  File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 1235, in to_sql
    assert len(stack) == 1
AssertionError

The attached patch fixes this issue in expression.py by checking for empty list of leaves beforehand and returns an empty WHERE clause in this case. It works because orm.py already checks for empty values.

Revision history for this message
Jean-Baptiste Quenot (jbq-caraldi) wrote :
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Jean-Baptiste, it would be interesting to see a sample query (e.g. a domain expression triggering the bug).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.