Skip to content

Commit 6720be4

Browse files
authored
billing: stop modifying subscription list that is being iterated over (PROJQUAY-8712) (quay#3725)
Fixes bug where removing a MW02702 sub after all it's quantities have been bound causes the next item in the subscription list to be skipped over, resulting in a malformed api response for the marketplace endpoint.
1 parent f0c153f commit 6720be4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

endpoints/api/billing.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,13 @@ def get(self):
11361136
)
11371137

11381138
child_subscriptions = []
1139+
subscriptions_to_return = []
1140+
11391141
for subscription in user_subscriptions:
11401142
bound_to_org, bindings = organization_skus.subscription_bound_to_org(subscription["id"])
11411143
# fill in information for whether a subscription is bound to an org
11421144
metadata = get_plan_using_rh_sku(subscription["sku"])
1145+
subscription["metadata"] = metadata
11431146
if bound_to_org:
11441147
# special case for MW02702, which can be split across orgs
11451148
if subscription["sku"] == "MW02702":
@@ -1161,19 +1164,16 @@ def get(self):
11611164
if remaining_unbound > 0:
11621165
subscription["quantity"] = remaining_unbound
11631166
subscription["assigned_to_org"] = None
1164-
else:
1165-
# all quantities for this subscription are bound, remove it from
1166-
# the response body
1167-
user_subscriptions.remove(subscription)
1167+
subscriptions_to_return.append(subscription)
11681168

11691169
else:
11701170
# default case, only one org is bound
11711171
subscription["assigned_to_org"] = model.organization.get_organization_by_id(
11721172
bindings[0]["org_id"]
11731173
).username
1174+
subscriptions_to_return.append(subscription)
11741175
else:
11751176
subscription["assigned_to_org"] = None
1177+
subscriptions_to_return.append(subscription)
11761178

1177-
subscription["metadata"] = metadata
1178-
1179-
return user_subscriptions + child_subscriptions
1179+
return subscriptions_to_return + child_subscriptions

0 commit comments

Comments
 (0)