Skip to content

Commit

Permalink
handle exception thrown by stripe when customer has no subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcusk19 committed Jan 30, 2025
1 parent c852217 commit 35843cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion workers/reconciliationworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ def _perform_reconciliation(self, user_api, marketplace_api):
except stripe.error.InvalidRequestError:
logger.warn("Invalid request for stripe_id %s", user.stripe_id)
continue
try:
subscription = stripe_customer.subscription
except AttributeError:
subscription = None
for sku_id in RECONCILER_SKUS:
if stripe_customer.subscription:
if subscription is not None:
plan = get_plan(stripe_customer.subscription.plan.id)
if plan is None:
continue
Expand Down
3 changes: 3 additions & 0 deletions workers/test/test_reconciliationworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_exception_handling(initialized_db):
with patch("data.billing.FakeStripe.Customer.retrieve") as mock:
mock.side_effect = stripe.error.APIConnectionError
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)
with patch("data.billing.FakeStripe.Customer.subscription") as mock:
mock.side_effect = AttributeError
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)


def test_create_for_stripe_user(initialized_db):
Expand Down

0 comments on commit 35843cc

Please sign in to comment.