From d98a683b2a389f05df2e83150e84e3b668f739ae Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 3 Jul 2018 23:23:02 +0200 Subject: [PATCH] Do a get on UserCardDetail only when fingerprint, exp_month and exp_year are known --- hosting/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index e1577bd8..b5fc9023 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -272,12 +272,16 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): :return: UserCardDetail object """ try: - card_detail = UserCardDetail.objects.get( - stripe_customer=stripe_customer, - fingerprint=card_details['fingerprint'], - exp_month=card_details['exp_month'], - exp_year=card_details['exp_year'] - ) + if ('fingerprint' in card_details and 'exp_month' in card_details + and 'exp_year' in card_details): + card_detail = UserCardDetail.objects.get( + stripe_customer=stripe_customer, + fingerprint=card_details['fingerprint'], + exp_month=card_details['exp_month'], + exp_year=card_details['exp_year'] + ) + else: + raise UserCardDetail.DoesNotExist() except UserCardDetail.DoesNotExist: preferred = False if 'preferred' in card_details: