[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#134596

X-original-commit: 0eb30132c14420d42f88a5f54a81ba1dc51a867c
Signed-off-by: Achraf Ben Azzouz (abz) <abz@odoo.com>
Signed-off-by: Saurabh Choraria (sauc) <sauc@odoo.com>
This commit is contained in:
Saurabh Choraria
2023-09-07 04:53:26 +00:00
parent 52af5b6d0a
commit f893eef973
2 changed files with 14 additions and 0 deletions
+10
View File
@@ -255,6 +255,16 @@ msgstr ""
msgid "Error at row %s: \"%s\""
msgstr ""
#. module: base_import
#. odoo-python
#: 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
#. odoo-javascript
#: code:addons/base_import/static/src/import_data_progress/import_data_progress.xml:0
+4
View File
@@ -1040,6 +1040,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:]