Skip to content
Snippets Groups Projects
Commit 62253417 authored by Saurabh Choraria's avatar Saurabh Choraria
Browse files

[FIX] base_import: raise ImportValidationError when invalid seperator selected

When a user tries to import the CSV file with a different separator at that
time, the values in mapper and rows_to_import are not correctly mapped. So
the traceback will be generated.

Steps to reproduce:
1. Click on import in the bank statement.
2. Select any CSV file for the bank statement line or can download and import
this file https://drive.google.com/file/d/1lnScw4RN6T01pOkyNON8vvb3FQOPiy1O/view?usp=drive_link


3. Select any separator other than a comma.
4. Click on the test or Import button.
5. Error will occur.

Error: IndexError: list index out of range.

To solve this issue, a row's length is checked with the
number of fields.

sentry-4021250095

closes odoo/odoo#131153

Signed-off-by: default avatarAchraf Ben Azzouz (abz) <abz@odoo.com>
parent 7b635c00
No related branches found
No related tags found
No related merge requests found
......@@ -293,6 +293,15 @@ msgstr ""
msgid "Error Parsing Date [%s:L%d]: %s"
msgstr ""
#. module: base_import
#: code:addons/base_import/models/base_import.py:0
#, python-format
msgid ""
"Error while importing records: all rows should be of the same size, but the "
"title row has %d entries while the first row has %d. You may need to change "
"the separator character."
msgstr ""
#. module: base_import
#. openerp-web
#: code:addons/base_import/static/src/legacy/xml/base_import.xml:0
......
......@@ -1039,6 +1039,10 @@ class Import(models.TransientModel):
import_fields = [f for f in fields if f]
_file_length, rows_to_import = self._read_file(options)
if len(rows_to_import[0]) != len(fields):
raise ImportValidationError(
_("Error while importing records: all rows should be of the same size, but the title row has %d entries while the first row has %d. You may need to change the separator character.", len(fields), len(rows_to_import[0]))
)
if options.get('has_headers'):
rows_to_import = rows_to_import[1:]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment