fields.py : correction on get() of O2M

Bug #603708 reported by Sébastien BEAU - http://www.akretion.com
24
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
Undecided
Unassigned
Trunk
Fix Released
Undecided
Unassigned

Bug Description

Hello
Maybe it's a server bug.

After installing Fleet Maintenance on a fresh installation.
I can't open the partner view if the field sub fleet of the partner is empty. (on a fresh install all partner have this field empty)

[2010-07-09 19:39:43,617] ERROR:web-services:[01]:
[2010-07-09 19:39:43,617] ERROR:web-services:[02]: Environment Information :
[2010-07-09 19:39:43,618] ERROR:web-services:[03]: System : Linux-2.6.32-23-generic-x86_64-with-Ubuntu-10.04-lucid
[2010-07-09 19:39:43,618] ERROR:web-services:[04]: OS Name : posix
[2010-07-09 19:39:43,618] ERROR:web-services:[05]: Distributor ID: Ubuntu
[2010-07-09 19:39:43,619] ERROR:web-services:[06]: Description: Ubuntu 10.04 LTS
[2010-07-09 19:39:43,619] ERROR:web-services:[07]: Release: 10.04
[2010-07-09 19:39:43,619] ERROR:web-services:[08]: Codename: lucid
[2010-07-09 19:39:43,620] ERROR:web-services:[09]: Operating System Release : 2.6.32-23-generic
[2010-07-09 19:39:43,620] ERROR:web-services:[10]: Operating System Version : #37-Ubuntu SMP Fri Jun 11 08:03:28 UTC 2010
[2010-07-09 19:39:43,620] ERROR:web-services:[11]: Operating System Architecture : 64bit
[2010-07-09 19:39:43,620] ERROR:web-services:[12]: Operating System Locale : fr_FR.UTF8
[2010-07-09 19:39:43,620] ERROR:web-services:[13]: Python Version : 2.6.5
[2010-07-09 19:39:43,621] ERROR:web-services:[14]: OpenERP-Server Version : 5.0.11
[2010-07-09 19:39:43,621] ERROR:web-services:[15]: Last revision No. & ID : 2083 <email address hidden>
[2010-07-09 19:39:43,621] ERROR:web-services:[16]:
[2010-07-09 19:39:43,622] ERROR:web-services:[17]: Traceback (most recent call last):
[2010-07-09 19:39:43,622] ERROR:web-services:[18]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/osv.py", line 58, in wrapper
[2010-07-09 19:39:43,622] ERROR:web-services:[19]: return f(self, dbname, *args, **kwargs)
[2010-07-09 19:39:43,622] ERROR:web-services:[20]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/osv.py", line 119, in execute
[2010-07-09 19:39:43,623] ERROR:web-services:[21]: res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
[2010-07-09 19:39:43,623] ERROR:web-services:[22]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/osv.py", line 111, in execute_cr
[2010-07-09 19:39:43,623] ERROR:web-services:[23]: return getattr(object, method)(cr, uid, *args, **kw)
[2010-07-09 19:39:43,623] ERROR:web-services:[24]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/orm.py", line 2228, in read
[2010-07-09 19:39:43,624] ERROR:web-services:[25]: result = self._read_flat(cr, user, select, fields, context, load)
[2010-07-09 19:39:43,624] ERROR:web-services:[26]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/orm.py", line 2360, in _read_flat
[2010-07-09 19:39:43,624] ERROR:web-services:[27]: res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
[2010-07-09 19:39:43,624] ERROR:web-services:[28]: File "/media/Mes_doc/DEV/openerp/ticket_anevia_fleet_250/server/bin/osv/fields.py", line 428, in get
[2010-07-09 19:39:43,625] ERROR:web-services:[29]: res[r[self._fields_id]].append(r['id'])
[2010-07-09 19:39:43,625] ERROR:web-services:[30]: KeyError: None

If you look in the server code function def get line 427
you can saw that we try to update the dictionary res but in my case the key "r[self._fields_id]" don't exist in res

==CODE==
    def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
        if not context:
            context = {}
        if self._context:
            context = context.copy()
        context.update(self._context)
        if not values:
            values = {}
        res = {}
        for id in ids:
            res[id] = []
        ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
        for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
             res[r[self._fields_id]].append(r['id']) <=== HERE ==========================
        return res
==CODE==

If you check the function def get_memory line 379 we check if this key exist before

==CODE==
    def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
        if not context:
            context = {}
        if self._context:
            context = context.copy()
            context.update(self._context)
        if not values:
            values = {}
        res = {}
        for id in ids:
            res[id] = []
        ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
        for r in obj.pool.get(self._obj).read(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
            if r[self._fields_id] in res:
                res[r[self._fields_id]].append(r['id']) <=== HERE ==========================
        return res
==CODE==

I think we have to check also in the function def get and I propose this patch.

Expert team in ORM what do you think about this?

Best regard

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :
Changed in openobject-addons:
status: New → Confirmed
Changed in openobject-addons:
assignee: nobody → RME(OpenERP) (rme-openerp)
Revision history for this message
Alexis de Lattre (alexis-via) wrote :

Is there a good reason not to merge the patch proposed by Sébastien ?

We are also affected by this bug, which prevent us from upgrading OpenERP to the latest stable 5.0.x versions.

Revision history for this message
Alexis de Lattre (alexis-via) wrote :

RME, what is your opinion about the proposed patch ? Is there a good reason not to merge it ? The patch has been written 2 months ago now, so a feedback from Tiny would be very much appreciated.

Revision history for this message
Samantha (samantha-z-mathews) wrote :

up

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

Sorry, as you can look in my first patch a ugly "if True" appear in the first line "if True : #r[self._fields_id] in res:". Just remove it (It was for testing).
Here is the patch without the "if True"

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Sébastien,

Fixed in : by

Stable : 2142 <email address hidden>
Trunk : 2864 <email address hidden>.

Thanks Sébastien for the patch.

summary: - [server][fleet maintenance] BUG when opening the partner menu
+ fields.py : correction on get() of O2M
affects: openobject-addons → openobject-server
Changed in openobject-server:
milestone: none → 5.0.15
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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