This question has been flagged

I have a little piece of one of my scripts that works perfectly fine on Python but always raise an IndexError under Odoo:

for nt in newTable:
    (the next line is obviously an extract of the newTable list)
nt = [21562, 7161, 'Cotto GR', '+ Muss. Vegetal', Decimal('1.0'), 'Mesa 05', 'A fazer', 'N', '0', datetime.datetime(2017, 2, 9, 10, 57, 27)]
items in list = 10
    self.env.cr.execute(sql_write_ord, (nt)) 
    self.env.cr.commit()

In python the syntax works fine, the nt list contains 10 items, as asked by the INSERT INTO sql call, but in odoo I get:

File "/odoo_test2/odoo_test2-server/addons/divina_v10/models/divina_pos_V10.py", line 111, in _compute_kot_lines self.env.cr.execute(sql_write_ord, (nt)) File "/odoo_test2/odoo_test2-server/odoo/sql_db.py", line 141, in wrapper return f(self, *args, **kwargs) File "/odoo_test2/odoo_test2-server/odoo/sql_db.py", line 218, in execute res = self._obj.execute(query, params)IndexError: tuple index out of range

For now I've tested with:

self.env.cr.execute(sql_write_ord, [nt[0], nt[1], nt[2], nt[3], nt[4], nt[5], nt[6], nt[7], nt[8], nt[9]])

and

self.env.cr.execute(sql_write_ord, ([tuple(nt)]))

but raise the same error.

Solved:

There are many logs on my code and I found the error of tuple index out of range is generated by the first tuple in newTable, This issue is not present under Python. To solve the problem I was obliged to flush newTable before starting to populate it, because the first list is created (and I still don't know why since in Python is fine) with just 7 items out of 10, then generate the error.  

Avatar
Discard
Author Best Answer

There are many logs on my code and I found the error of tuple index out of range is generated by the first tuple in newTable, This issue is not present under Python. To solve the problem I was obliged to flush newTable before starting to populate it, because the first list is created (and I still don't know why since in Python is fine) with just 7 items out of 10, then generate the error.

Avatar
Discard
Best Answer

Hi,

please try self.env.cr.execute(sql_write_ord, ([tuple(nt)]))

Avatar
Discard
Author

Hi Hilar,

I've already tried with ([tuple(nt)]), it will not working on Python.

I've tried with single items too:

(sql_write_ord, [nt[0], nt[1], nt[2], nt[3], nt[4], nt[5], nt[6], nt[7], nt[8], nt[9]])

that solution it's working on Python but not on Odoo.

Again why Odoo can't read my list of lists?

Try this syntax then,

cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)

SELECT name, lang, res_id, src, type, value, module, state, comments

FROM %s AS ti

WHERE NOT EXISTS(SELECT 1 FROM ONLY %s AS irt WHERE %s);

""" % (self._model_table, self._table, self._model_table, find_expr))

Please check here how the values are given and try to add your values as per this syntax

Author

Hilar, thanks to have drive my mind where the error is.

Seems Odoo is jumping some passages on my script.

I'va added a series of logs and I can clearly see that the list is not populated correctly. Again this is part of a large script i run as a daemon that works perfectly fine under Python (since 2015) and Odoo 8 / 9 / 10.

I need to look elsewhere, probably there is something bothering Oddo where my list is created.

Author

Solved with a second round of flush before starting to populate the list. Kind of weird, but it's working.