From 6cac1d5a25aed44c43e5843b9103273f670472d7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 6 Feb 2020 20:17:49 -0800 Subject: [PATCH] Show all missing columns when raising the missing error. --- voussoirkit/sqlhelpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/voussoirkit/sqlhelpers.py b/voussoirkit/sqlhelpers.py index 8a4209e..533c3b2 100644 --- a/voussoirkit/sqlhelpers.py +++ b/voussoirkit/sqlhelpers.py @@ -48,13 +48,16 @@ def insert_filler(column_names, values, require_all=True): cur.execute(query, bindings) ''' values = values.copy() + missings = [] for column in column_names: if column in values: continue if require_all: - raise ValueError('Missing column "%s"' % column) + missings.append(column) else: values[column] = None + if missings: + raise ValueError(f'Missing columns {missings}.') qmarks = '?' * len(column_names) qmarks = ', '.join(qmarks) bindings = [values[column] for column in column_names]