From 906aa2e5cc3af1cb5275a58d2156feea7692357e Mon Sep 17 00:00:00 2001 From: higs4281 Date: Thu, 1 Jun 2017 18:51:37 -0400 Subject: [PATCH] Catch missing URL values in cost-error model method We've encountered a few disclosure URLs that were missing some fields. This uses the dictionary get() method, which should have been used in the first place, to avoid key errors when running reports. --- paying_for_college/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/paying_for_college/models.py b/paying_for_college/models.py index 7e31716..ab00f50 100755 --- a/paying_for_college/models.py +++ b/paying_for_college/models.py @@ -400,8 +400,10 @@ def total_fields(field_list): def cost_error(self): """Return 1 or 0: Is total-cost less than tuition?""" url_data = self.parsed_url - if url_data and url_data['totl'] != '' and url_data['tuit'] != '': - if int(url_data['totl']) < int(url_data['tuit']): + if (url_data + and url_data.get('totl') != '' + and url_data.get('tuit') != ''): + if int(url_data.get('totl', 0)) < int(url_data.get('tuit', 0)): return 1 else: return 0