import_data() does not work for many2many multiple values on object xml_id

Asked by Colin MacMillan

according to the technical memento, you should be able to reference multiple xml_id in the same field for many2many fields but it does not work.

this works fine with the database_id

see attached example modules

to recreate the problem:
1) create a BASE system with no demo data
2) install 'import_mod_problem' module first
3) install 'import_mod_problem_data' second to see error

[2011-06-09 16:48:37,163][test_import_error_final] ERROR:web-services:Uncaught exception
Traceback (most recent call last):
  File "/home/openerp/openerp6/openobject-server/bin/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/openerp/openerp6/openobject-server/bin/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/openerp/openerp6/openobject-server/bin/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/openerp/openerp6/openobject-server/bin/addons/base/module/wizard/base_module_upgrade.py", line 98, in upgrade_module
    _db, pool = pooler.restart_pool(cr.dbname, update_module=True)
  File "/home/openerp/openerp6/openobject-server/bin/pooler.py", line 60, in restart_pool
    return get_db_and_pool(db_name, force_demo, status, update_module=update_module)
  File "/home/openerp/openerp6/openobject-server/bin/pooler.py", line 39, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
  File "/home/openerp/openerp6/openobject-server/bin/addons/__init__.py", line 883, in load_modules
    processed_modules.extend(load_module_graph(cr, graph, status, report=report, skip_modules=processed_modules))
  File "/home/openerp/openerp6/openobject-server/bin/addons/__init__.py", line 748, in load_module_graph
    load_init_update_xml(cr, m, idref, mode, kind)
  File "/home/openerp/openerp6/openobject-server/bin/addons/__init__.py", line 635, in load_init_update_xml
    tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate)
  File "/home/openerp/openerp6/openobject-server/bin/tools/convert.py", line 947, in convert_csv_import
    result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)
  File "/home/openerp/openerp6/openobject-server/bin/osv/orm.py", line 868, in import_data
    process_liness(self, datas, [], current_module, self._name, fields_def, position=position)
  File "/home/openerp/openerp6/openobject-server/bin/osv/orm.py", line 830, in process_liness
    res.append( _get_id(relation, db_id, current_module, mode) )
  File "/home/openerp/openerp6/openobject-server/bin/osv/orm.py", line 732, in _get_id
    record_id = ir_model_data_obj._get_id(cr, uid, module, xml_id)
  File "/home/openerp/openerp6/openobject-server/bin/tools/misc.py", line 823, in cached_result
    result2 = fn(self2, cr, *args[:self.skiparg-2], **kwargs2)
  File "/home/openerp/openerp6/openobject-server/bin/addons/base/ir/ir_model.py", line 602, in _get_id
    raise ValueError('No references to %s.%s' % (module, xml_id))

openobject-server - 6.0.2 - revno 3403
openobject-addons - 6.0.2 - revno 4535

thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Vinay Rana (OpenERP)
Solved:
Last query:
Last reply:
Revision history for this message
Colin MacMillan (colin-macmillan) said :
#1

second file

Revision history for this message
Best Vinay Rana (OpenERP) (vra-openerp) said :
#2

Hello ,

I have checked your attached module but you have not configured the proper csv file for many2many relation import so following file content will easily imported when you will install the related attached module:

object_a.csv

"id","name","relation"
"id1","j","a,b,c"
"id2","k","a,b,d"
"id3","l","a,b,e"
"id4","m","a,b,e"
"id5","n","a,b,e"
"id6","o","a,b,e"

Hope this will help you.

Thanks.

Revision history for this message
Colin MacMillan (colin-macmillan) said :
#3

Hello Vinay,

Yes thank you absolutely correct. I have now tried all 3 methods - many2many_field, many2many_field:id, and many2many.id all working fine.

My problem was putting a <space> after each comma.

Lesson of the day - Don't put a space in CSV imports!!!

Appreciate the fast response.

regards
Colin

Revision history for this message
Colin MacMillan (colin-macmillan) said :
#4

Thanks Vinay Rana (openerp), that solved my question.