convert enumerate/generator into list before checking it't not empty (#32259)

This commit is contained in:
Frédéric Péters 2019-04-13 10:22:58 +02:00 committed by Christophe Siraut
parent 0ef61ec694
commit f628a6b6fd
1 changed files with 4 additions and 1 deletions

View File

@ -402,8 +402,11 @@ CREATE TABLE public.dates AS (SELECT
ids = range(next_id, next_id + len(to_insert))
labels = zip(ids, to_insert)
if labels:
if labels is not None:
# turn enumerate generator object into a proper list
labels = list(labels)
if labels:
tmpl = ', '.join(['(%s, %s)'] * len(labels))
query_str = 'INSERT INTO {name} (id, label) VALUES %s' % tmpl
self.ex(query_str, ctx={'name': name}, vars=list(itertools.chain(*labels)))