Merge lp:~openerp-dev/openobject-server/6.0-opw-51206-vro into lp:openobject-server/6.0

Proposed by Valencia Rodrigues (OpenERP)
Status: Merged
Merge reported by: Olivier Laurent (Open ERP)
Merged at revision: not available
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-51206-vro
Merge into: lp:openobject-server/6.0
Diff against target: 15 lines (+4/-1)
1 file modified
bin/osv/orm.py (+4/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-51206-vro
Reviewer Review Type Date Requested Status
Serpent Consulting Services (community) Needs Fixing
Vinay Rana (OpenERP) (community) Approve
Rifakat Husen (OpenERP) (community) Approve
Review via email: mp+85792@code.launchpad.net

Description of the change

Hello,

Import of datas was recently improved to allow import of inactive records (revision: 3547). But this presumed that the 'active' field is present in the object. Hence, import results in the following traceback for objects without the field 'active':

Environment Information :
System : Windows-XP-5.1.2600-SP3
OS Name : nt
Operating System Release : XP
Operating System Version : 5.1.2600
Operating System Architecture : 32bit
Operating System Locale : nl_NL.cp1252
Python Version : 2.5.2
OpenERP-Client Version : 6.0.2
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "/home/odoo/openerp/server/bin/netsvc.py", line 490, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
  File "/home/odoo/openerp/server/bin/addons/use_control/services.py", line 41, in dispatch
    return super(recording_objects_proxy, self).dispatch(func, auth, params)
  File "/home/odoo/openerp/server/bin/service/web_services.py", line 654, in dispatch
    res = fn(db, uid, *params)
  File "/home/odoo/openerp/server/bin/addons/audittrail/audittrail.py", line 522, in execute
    res = my_fct(db, uid, model, method, *args)
  File "/home/odoo/openerp/server/bin/addons/audittrail/audittrail.py", line 500, in my_fct
    return fct_src(db, uid_orig, model, method, *args)
  File "/home/odoo/openerp/server/bin/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/odoo/openerp/server/bin/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/odoo/openerp/server/bin/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 870, in import_data
    process_liness(self, datas, [], current_module, self._name, fields_def, position=position)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 820, in process_liness
    res = _get_id(relation, line[i], current_module, mode)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 726, in _get_id
    ids = obj_model.search(cr, uid, [('id', '=', int(id)),('active','in',['True','False'])], context=context)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 1745, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 4016, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/home/odoo/openerp/server/bin/osv/orm.py", line 3871, in _where_calc
    where_clause, where_params = e.to_sql()
  File "/home/odoo/openerp/server/bin/osv/expression.py", line 490, in to_sql
    q, p = self.__leaf_to_sql(e, table)
  File "/home/odoo/openerp/server/bin/osv/expression.py", line 416, in __leaf_to_sql
    instr = ','.join([table._columns[left]._symbol_set[0]] * len_after)
KeyError: 'active'

This fix resolves the error.

Thanks

To post a comment you must log in.
Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Really good catch, Works correctly.

Thanks.

review: Approve
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

I have checked this issue and for solving the regression the propose fixes works.

review: Approve
Revision history for this message
Serpent Consulting Services (serpent-consulting-services) wrote :

Valencia,

There is still a scope of improvements here.

Here they are:
1. Use only once the expression int(id). The use of int(id) in the domain is not necessary, better to say useless.

2. You can always use minimal code by just updating the domain, rest of the things would go intact.

dom = [('id', '=', id)]
if obj_model._columns.get('active'):
   dom.append(Your TEST)
ids = obj_model.search(cr, uid, dom, context=context)

This makes the code look cleaner.

Thanks,
Serpent Consulting Services.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/osv/orm.py'
2--- bin/osv/orm.py 2011-11-24 12:52:13 +0000
3+++ bin/osv/orm.py 2011-12-15 05:57:25 +0000
4@@ -723,7 +723,10 @@
5 if mode=='.id':
6 id = int(id)
7 obj_model = self.pool.get(model_name)
8- ids = obj_model.search(cr, uid, [('id', '=', int(id)),('active','in',['True','False'])], context=context)
9+ if obj_model._columns.get('active'):
10+ ids = obj_model.search(cr, uid, [('id', '=', int(id)),('active','in',['True','False'])], context=context)
11+ else:
12+ ids = obj_model.search(cr, uid, [('id', '=', int(id))], context=context)
13 if not len(ids):
14 raise Exception(_("Database ID doesn't exist: %s : %s") %(model_name, id))
15 elif mode=='id':