question 357 Memory & Python Internals · medium
Fix the error list that grows across rows
An import job validates each row with collect_errors. The first bad row reports one error, but every later row reports the errors of all the rows before it, even rows that are perfectly fine. Fix the function. Callers may still pass their own list to collect into.
Function
collect_errors(row, errors=None)Checks
"missing order_id" when order_id is missing or empty; "negative total" when total is below 0Returnsthe list the errors were appended to: the caller's list if one was given, otherwise a new list
Examples
callcollect_errors({'order_id': '', 'total': 12.5})returns['missing order_id']
callcollect_errors({'order_id': 'O100282', 'total': 35.84})returns[]
callcollect_errors({'total': -3})returns['missing order_id', 'negative total']