[6.0rc2] csv import data mangled (with solution)

Bug #698354 reported by Martin Collins
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Low
OpenERP's Framework R&D

Bug Description

Many2one fields with name are getting related to the wrong objects with hilarious/disastrous results.
e.g. my res.users.csv specified menu_id of 'Menu' but got 'Board Create Menu' resulting in complete lockout :-(

The problem is name_search() is building this query:

   SELECT "ir_actions".id FROM "ir_actions" WHERE (ir_actions.name ilike E'%Menu%') ORDER BY name limit 100

The use of 'ilike' means that if there is more than one action with 'Menu' in the name then it is pot-luck which one you get and more than likely chaos will ensue.
The match must be exact, so the operator must be specified as '=', thus:

=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py 2010-12-29 18:25:09 +0000
+++ bin/osv/orm.py 2011-01-06 22:00:15 +0000
@@ -726,7 +726,7 @@
                 id = ir_model_data[0]['res_id']
             else:
                 obj_model = self.pool.get(model_name)
- ids = obj_model.name_search(cr, uid, id)
+ ids = obj_model.name_search(cr, uid, id, operator='=')
                 if not ids:
                     raise ValueError('No record found for %s' % (id,))
                 id = ids[0][0]

Related branches

Revision history for this message
xrg (xrg) wrote : Re: [Bug 698354] [NEW] [6.0rc2] csv import data mangled (with solution)

On Friday 07 January 2011, you wrote:
> The use of 'ilike' means that if there is more than one action with 'Menu'
> in the name then it is pot-luck which one you get and more than likely
> chaos will ensue. The match must be exact, so the operator must be
> specified as '=', thus:

Seems right. Well done.

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

Martin, thanks a lot for the bug report and the patch! Your patch was merged in server revision 3262 <email address hidden>

Changed in openobject-server:
milestone: none → 6.0
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

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