[v6rc2] orm read() fails when no fields-list passed, on objects that override parent columns

Bug #701013 reported by fc
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

Hello,

The "project" module has been modified since rc1, among other things, the field "parent_id" is now a "project.project" and doing a XMLRPC read on a project having this field set now leads to a server error, as described below.

Steps to reproduce:
  * install v6rc2 with the project module
  * create two projects "foo" (id 1) and "bar" (id 2) having "foo" as parent
  * execute(1,"read") => succeeds
  * execute(2,"read","parent_id") => succeeds
  * execute(2,"read") => FAILS with the following error:
---
[2011-01-10 14:03:12,035][main] ERROR:db.cursor:Programming error: arguments of row IN must all be row expressions
LINE 1: ...d FROM "project_project" WHERE project_project.id IN ((1, E'...
                                                             ^
, in query SELECT project_project.analytic_account_id,project_project.id FROM "project_project" WHERE project_project.id IN %s ORDER BY sequence
[2011-01-10 14:03:12,036][main] ERROR:web-services:Uncaught exception
Traceback (most recent call last):
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/osv.py", line 177, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/orm.py", line 2920, in read
    result = self._read_flat(cr, user, select, fields, context, load,indent+" ")
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/orm.py", line 3058, in _read_flat
    res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res,indent=indent+" ")
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/fields.py", line 362, in get
    records = dict(obj.name_get(cr, 1, list(set(filter(None, res.values()))), context=context,indent=indent))
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/orm.py", line 1766, in name_get
    [self._rec_name], context, load='_classic_write',indent=indent)]
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/orm.py", line 2920, in read
    result = self._read_flat(cr, user, select, fields, context, load,indent+" ")
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/osv/orm.py", line 2984, in _read_flat
    cr.execute(query, (tuple(sub_ids),))
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/sql_db.py", line 76, in wrapper
    return f(self, *args, **kwargs)
  File "/home/user/Documents/openerp-server-6.0.0-rc2/bin/sql_db.py", line 129, in execute
    res = self._obj.execute(query, params)
ProgrammingError: arguments of row IN must all be row expressions
LINE 1: ...d FROM "project_project" WHERE project_project.id IN ((1, E'...
                                                             ^

[2011-01-10 14:03:12,039][main] DEBUG_RPC:exception:u'arguments of row IN must all be row expressions\nLINE 1: ...d FROM "project_project" WHERE project_project.id IN ((1, E\'...\n ^\n'
[2011-01-10 14:03:12,040][main] DEBUG_RPC:xmlrpc:"POST /object HTTP/1.0" 200 -
---

As it occurs in sql_db.py, it is not specific to the project module as far as I understand the issue.

Adding some trace in orm.py:_flat_read() show the query to be:
SELECT project_project.analytic_account_id,project_project.id FROM "project_project" WHERE project_project.id IN %s ORDER BY sequence
with args= ((1, u'foo'),), where a list of ints is expected.

Somehow there's no impact on the user interface (so far), I guess the client doesn't use a full read() but read each field separately.

Related branches

Revision history for this message
fc (fc-tempo-consulting) wrote :

I think I found the issue:
In orm.py:read(), if no "fields" argument is passed, the set of all fields (local and inherited) is computed. This lead to a problem when the same field has been redefined: in that case, "fields" contains several entries with the same name which can't work with the read()/_flat_read() logic [which reuse the same structure completed with the fields values if I understand correctly].
Anyway, simply adding [line 2916] something like:
---
fields=list(set(fields))
---
to eliminate duplicates solves this problem.

summary: - [v6rc2] orm/sql_db.py bug
+ [v6rc2] orm read() bug
summary: - [v6rc2] orm read() bug
+ [v6rc2] orm read() bug on redefined fields
Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote : Re: [v6rc2] orm read() bug on redefined fields

Hello,

When we are trying to read the record of "project.project" object which contains the value for "parent_id" field, the traceback occurred as specified in the bug. So I am confirming this bug.

I am not sure whether it is coming due to the use of _inherits in "project.project" object as it always wants the parent_id of the record at the time of reading that object. If we provide that parent_id, things are working normal.

Thanks.

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello fc,

Your analysis and patch are perfectly correct! Indeed, read_flat() has a step to post-process special fields, like many2one, who are not directly returned as stored in the database. This post-processing step is not meant to be re-entrant, so when the field is requested twice, it can break in various ways. And as you noticed, when an osv object redefines one of its parent's column, read() did not remove the duplicates field names, when a read() call is issued without the list of fields to read.

This is fixed as of revision 3255 (<email address hidden>) of the server, and in addition to your suggested patch we also strengthened the underlying m2o.get, to cover other similar cases.

Many thanks!

Changed in openobject-server:
milestone: none → 6.0
status: Confirmed → Fix Released
summary: - [v6rc2] orm read() bug on redefined fields
+ [v6rc2] orm read() fails when no fields-list pass on objects that
+ override parent columns
summary: - [v6rc2] orm read() fails when no fields-list pass on objects that
+ [v6rc2] orm read() fails when no fields-list passed, on objects that
override parent columns
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.