passing ids as integer to account.account write method throws KeyError: "Field '0' does not exist in object 'browse_record'...

Bug #812723 reported by Simone Orsi
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Addons Team 3

Bug Description

If "ids" is passed to write as integer instead of a list you get this:

Traceback (most recent call last):
  File "/home/simahawk/dev/openobject/stable/server/bin/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/simahawk/dev/openobject/stable/server/bin/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/simahawk/dev/openobject/stable/server/bin/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/simahawk/dev/openobject/stable/server/bin/addons/account/account.py", line 552, in write
    self._check_allow_type_change(cr, uid, ids, vals['type'], context=context)
  File "/home/simahawk/dev/openobject/stable/server/bin/addons/account/account.py", line 525, in _check_allow_type_change
    for account in self.browse(cr, uid, ids, context=context):
  File "/home/simahawk/dev/openobject/stable/server/bin/osv/orm.py", line 189, in __getitem__
    name, self))
KeyError: "Field '0' does not exist in object 'browse_record(account.account, 33)'"

as you can see the error occurs into _check_allow_type_change whereas at line 523 [1]:

for account in self.browse(cr, uid, ids, context=context):

the problem can be easily solved using:

if not isinstance(ids,list):
    ids = [ids,]
for account in self.browse(cr, uid, ids, context=context):

The weird thing is that also at line 544 [2] we have:

if 'company_id' in vals:
            move_lines = self.pool.get('account.move.line').search(cr, uid, [('account_id', 'in', ids)])
            if move_lines:
                # Allow the write if the value is the same
                for i in [i['company_id'][0] for i in self.read(cr,uid,ids,['company_id'])]:

beside the horrible nested for.... this *is going to fail* whenever ids is not a list.

I supposed you've been lucky till here because probably when 'company_id' is in vals you have always a list...

This bug is similar to https://bugs.launchpad.net/openobject-addons/+bug/740202

[1] http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/account/account.py#L523
[2] http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/account/account.py#L544

Tags: account

Related branches

Amit Parik (amit-parik)
Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
importance: Undecided → Low
status: New → Confirmed
Changed in openobject-addons:
status: Confirmed → In Progress
Revision history for this message
Bharat Devnani (Open ERP) (bde-openerp) wrote :

Hello Simone Orsi,

Thanks for Reporting and contribution, Following are the Revision ID and Number of the bug :

Revision ID : <email address hidden>
Revision Number : 4890

The solution will be merged in addons soon.

Thanks & Regards,
Devnani Bharat R.

Changed in openobject-addons:
status: In Progress → Fix Committed
Changed in openobject-addons:
milestone: none → 6.1
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

fixed, but I think it's a bad idea to allow putting int instead of list in write methods.
this could be changed in v7.0 ?

Changed in openobject-addons:
status: Fix Committed → Fix Released
Revision history for this message
qdp (OpenERP) (qdp) wrote :

released in revno 5071

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.