Skip to content

Commit

Permalink
fix: make subscription plans editable again
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pwnage101 committed Jan 31, 2024
1 parent 430a3e8 commit d760d35
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions license_manager/apps/subscriptions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d760d35

Please sign in to comment.