Skip to content

Commit c0159ee

Browse files
authored
Merge pull request #84 from networktocode/mzb-develop-2.0-fix-race
Async task race condition fix
2 parents 12694d6 + 59e1c62 commit c0159ee

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, CSVModelForm
@@ -162,5 +163,7 @@ def save(self, commit=True, **kwargs):
162163
model = super().save(commit=commit, **kwargs)
163164
if commit:
164165
credentials = Credentials(self.data.get("username"), self.data.get("password"), self.data.get("secret"))
165-
get_queue("default").enqueue("netbox_onboarding.worker.onboard_device", model.pk, credentials)
166+
transaction.on_commit(
167+
lambda: get_queue("default").enqueue("netbox_onboarding.worker.onboard_device", model.pk, credentials)
168+
)
166169
return model

0 commit comments

Comments
 (0)