From d760d35ccb9d46e8baf0e1ba389366436fe1c1b1 Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Wed, 31 Jan 2024 13:14:35 -0800 Subject: [PATCH] fix: make subscription plans editable again Subscription plan creation worked because desired_num_licenses was always non-null, but it's not possible to edit an existing plan (some of them do have null values for desired_num_licenses) due to the following error: ``` num_new_licenses = obj.desired_num_licenses - obj.num_licenses TypeError: unsupported operand type(s) for -: 'NoneType' and 'int' ``` ENT-8269 --- license_manager/apps/subscriptions/admin.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/license_manager/apps/subscriptions/admin.py b/license_manager/apps/subscriptions/admin.py index ef0b1d57..d72b7dad 100644 --- a/license_manager/apps/subscriptions/admin.py +++ b/license_manager/apps/subscriptions/admin.py @@ -354,13 +354,16 @@ def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) - num_new_licenses = obj.desired_num_licenses - obj.num_licenses - if num_new_licenses <= PROVISION_LICENSES_BATCH_SIZE: - # We can handle just one batch synchronously. - SubscriptionPlan.increase_num_licenses(obj, num_new_licenses) - else: - # Multiple batches of licenses will need to be created, so provision them asynchronously. - provision_licenses_task.delay(subscription_plan_uuid=obj.uuid) + # Finally, provision any additional licenses if necessary. + if obj.desired_num_licenses: + license_count_gap = obj.desired_num_licenses - obj.num_licenses + if license_count_gap > 0: + if license_count_gap <= PROVISION_LICENSES_BATCH_SIZE: + # We can handle just one batch synchronously. + SubscriptionPlan.increase_num_licenses(obj, license_count_gap) + else: + # Multiple batches of licenses will need to be created, so provision them asynchronously. + provision_licenses_task.delay(subscription_plan_uuid=obj.uuid) @admin.register(CustomerAgreement)