From 587e18d2efa7f01a1a54ccca171e7a9add9d5d43 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 6 Dec 2017 22:00:45 +0000 Subject: [PATCH] Lookup index, rather than iterating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since instances of `Recipients` are now iterable we can just look up the first row by index, rather than having to hit the rows property as a generator. There is a chance that there won’t be a first row, if the file has 1 or fewer columns. So we still need to handle a possible exception (albeit it a different one to before). --- app/main/views/send.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index d53053ed9..305f5a107 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -521,8 +521,8 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False): back_link = url_for('.send_messages', service_id=service_id, template_id=template.id) choose_time_form = ChooseTimeForm() - with suppress(StopIteration): - template.values = next(recipients.rows) + with suppress(IndexError): + template.values = recipients[0] session['upload_data']['notification_count'] = len(list(recipients.rows)) session['upload_data']['valid'] = not recipients.has_errors