Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

corporate: Exclude non-realm Customer objects in downgrade small realms.

Lauryn Menard37b70a8e2493
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 31a9a1f45f3..45005e431b5 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1116,7 +1116,7 @@ def customer_has_last_n_invoices_open(customer: Customer, n: int) -> bool:
def downgrade_small_realms_behind_on_payments_as_needed() -> None:
- customers = Customer.objects.all().exclude(stripe_customer_id=None)
+ customers = Customer.objects.all().exclude(stripe_customer_id=None).exclude(realm=None)
for customer in customers:
realm = customer.realm
assert realm is not None
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index acafcb8d815..0ea8eecb157 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -3789,6 +3789,15 @@ class StripeTest(StripeTestCase):
)
rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
+ # Customer objects without a realm should be excluded from query.
+ remote_server = RemoteZulipServer.objects.create(
+ uuid=str(uuid.uuid4()),
+ api_key="magic_secret_api_key",
+ hostname="demo.example.com",
+ contact_email="[email protected]",
+ )
+ Customer.objects.create(remote_server=remote_server, stripe_customer_id="cus_xxx")
+
with patch("corporate.lib.stripe.void_all_open_invoices") as void_all_open_invoices_mock:
downgrade_small_realms_behind_on_payments_as_needed()