Skip to content

Commit

Permalink
fix: avoid race condition on plan-license async creation
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed May 9, 2024
1 parent 4c0d546 commit 4b1e847
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion license_manager/apps/subscriptions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,12 @@ def save_model(self, request, obj, form, change):
if not change:
obj.desired_num_licenses = form.cleaned_data.get('num_licenses', 0)

super().save_model(request, obj, form, change)
# If the desired number of licenses is large enough, we trigger an async celery task
# after the creation of this record. We wrap that creation in a transaction here
# to force a commit, so that the async task does not encounter a race condition
# where the plan it expects to read from the DB does not yet exist.
with transaction.atomic():
super().save_model(request, obj, form, change)

# Finally, if we're creating the model instance, go ahead and create the related license records.
if not change:
Expand Down

0 comments on commit 4b1e847

Please sign in to comment.