Skip to content

Commit 59e1c62

Browse files
committed
fix async task race condition
1 parent 813ff83 commit 59e1c62

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

netbox_onboarding/forms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
from django import forms
16+
from django.db import transaction
1617
from django_rq import get_queue
1718

1819
from utilities.forms import BootstrapMixin
@@ -156,5 +157,7 @@ def save(self, commit=True, **kwargs):
156157
model = super().save(commit=commit, **kwargs)
157158
if commit:
158159
credentials = Credentials(self.data.get("username"), self.data.get("password"), self.data.get("secret"))
159-
get_queue("default").enqueue("netbox_onboarding.worker.onboard_device", model.pk, credentials)
160+
transaction.on_commit(
161+
lambda: get_queue("default").enqueue("netbox_onboarding.worker.onboard_device", model.pk, credentials)
162+
)
160163
return model

0 commit comments

Comments
 (0)