orm: at csv import, properly report lines with less columns
authorP. Christeas <p_christ@hol.gr>
Wed, 20 Apr 2011 15:24:13 +0000 (18:24 +0300)
committerP. Christeas <p_christ@hol.gr>
Wed, 20 Apr 2011 15:24:13 +0000 (18:24 +0300)
The "if not line[i]" check would cause an IndexError earlier than the
exception. Also, report the line number where that happened.
(the +2 op. is needed because we skip 1 for header and count at 0)
(cherry picked from commit 7f7e84e32405d4552b8f1b156d359d629bbca353)

bzr revid: p_christ@hol.gr-20110420152413-knedwepb0tmersw4

bin/osv/orm.py

index 91574e7..947d902 100644 (file)
@@ -762,10 +762,12 @@ class orm_template(object):
             done = {}
             for i in range(len(fields)):
                 res = False
+                if i >= len(line):
+                    raise Exception(_('Please check that all your lines have %d columns.'
+                        'Stopped around line %d having %d columns.') % \
+                            (len(fields), position+2, len(line)))
                 if not line[i]:
                     continue
-                if i >= len(line):
-                    raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))
 
                 field = fields[i]
                 if field[:len(prefix)] <> prefix: