From d399fe6e7915eaa2305e397572716afb1937a7d5 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 15 Nov 2019 12:24:39 +0530 Subject: [PATCH] Handle DoesNotExist better --- utils/hosting_utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 9492e1de..d3492a64 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -151,17 +151,20 @@ def ping_ok(host_ipv6): def get_vat_rate_for_country(country): - vat_rate = VATRates.objects.get( - territory_codes=country, start_date__isnull=False, stop_date=None - ) - if vat_rate: + vat_rate = None + try: + vat_rate = VATRates.objects.get( + territory_codes=country, start_date__isnull=False, stop_date=None + ) logger.debug("VAT rate for %s is %s" % (country, vat_rate.rate)) return vat_rate.rate - else: + except VATRates.DoesNotExist as dne: + logger.debug(str(dne)) logger.debug("Did not find VAT rate for %s, returning 0" % country) return 0 + class HostingUtils: @staticmethod def clear_items_from_list(from_list, items_list):