better import errors (issue 1368)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.6.0-development+timestamp.2013.09.01.13.11.38
|
Version 2.6.0-development+timestamp.2013.09.01.13.34.22
|
||||||
|
|||||||
+15
-10
@@ -8881,24 +8881,31 @@ class Table(object):
|
|||||||
|
|
||||||
first = True
|
first = True
|
||||||
unique_idx = None
|
unique_idx = None
|
||||||
for line in reader:
|
for lineno, line in enumerate(reader):
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
if not colnames:
|
if not colnames:
|
||||||
|
# assume this is the first line of the input, contains colnames
|
||||||
colnames = [x.split('.',1)[-1] for x in line][:len(line)]
|
colnames = [x.split('.',1)[-1] for x in line][:len(line)]
|
||||||
cols, cid = [], None
|
cols, cid = [], None
|
||||||
for i,colname in enumerate(colnames):
|
for i,colname in enumerate(colnames):
|
||||||
if is_id(colname):
|
if is_id(colname):
|
||||||
cid = i
|
cid = i
|
||||||
else:
|
elif colname in self.fields:
|
||||||
cols.append(i)
|
cols.append((i,self[colname]))
|
||||||
if colname == unique:
|
if colname == unique:
|
||||||
unique_idx = i
|
unique_idx = i
|
||||||
else:
|
else:
|
||||||
items = [fix(self[colnames[i]], line[i], id_map, id_offset) \
|
# every other line contains instead data
|
||||||
for i in cols if colnames[i] in self.fields]
|
items = []
|
||||||
|
for i, field in cols:
|
||||||
|
try:
|
||||||
|
items.append(fix(field, line[i], id_map, id_offset))
|
||||||
|
except ValueError:
|
||||||
|
raise RuntimeError("Unable to parse line:%s field:%s value:'%s'"
|
||||||
|
% (lineno+1,field,line[i]))
|
||||||
|
|
||||||
if not id_map and cid is not None and id_offset is not None and not unique_idx:
|
if not (id_map or cid is None or id_offset is None or unique_idx):
|
||||||
csv_id = long(line[cid])
|
csv_id = long(line[cid])
|
||||||
curr_id = self.insert(**dict(items))
|
curr_id = self.insert(**dict(items))
|
||||||
if first:
|
if first:
|
||||||
@@ -8906,10 +8913,8 @@ class Table(object):
|
|||||||
# First curr_id is bigger than csv_id,
|
# First curr_id is bigger than csv_id,
|
||||||
# then we are not restoring but
|
# then we are not restoring but
|
||||||
# extending db table with csv db table
|
# extending db table with csv db table
|
||||||
if curr_id>csv_id:
|
id_offset[self._tablename] = (curr_id-csv_id) \
|
||||||
id_offset[self._tablename] = curr_id-csv_id
|
if curr_id>csv_id else 0
|
||||||
else:
|
|
||||||
id_offset[self._tablename] = 0
|
|
||||||
# create new id until we get the same as old_id+offset
|
# create new id until we get the same as old_id+offset
|
||||||
while curr_id<csv_id+id_offset[self._tablename]:
|
while curr_id<csv_id+id_offset[self._tablename]:
|
||||||
self._db(self._db[self][colnames[cid]] == curr_id).delete()
|
self._db(self._db[self][colnames[cid]] == curr_id).delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user